Collection View outline shows under and over my horizontal collection - xamarin

I have problem with CollectionView outline. I create simple horizontal colletionView, and it is working, but on top and bottom I have gray outline.
XAML
<CollectionView BackgroundColor="White"
Margin="0,15,0,0"
x:Name="NewSubMenu"
ItemsLayout="HorizontalList"
SelectionMode="Single"
HeightRequest="35"
SelectionChanged="OnCollectionViewSelectionChanged"
ItemsSource="{Binding MyListSource}"
HorizontalOptions="FillAndExpand">
<CollectionView.ItemTemplate >
<DataTemplate>
<Grid BackgroundColor="White" >
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal" />
<VisualState Name="Selected" >
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="White" />
<Setter TargetName="_label" Property="Label.TextColor" Value="Black" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Label Text="{Binding Name}"
x:Name="_label" ClassId="{Binding Id}"
TextColor="{StaticResource TamnoBraon}"
TextTransform="Uppercase" Padding="5,1,10,1" FontSize="Large"></Label>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Does anyone have same problem?

Related

I want to change the shape of the radio button, can I change the border size?

<ContentPage.Resources>
<ControlTemplate x:Key="FrameRadioTemplate">
<Frame
Padding="10"
BackgroundColor="{DynamicResource ColorBorder000}"
BorderColor="Red"
HeightRequest="50"
WidthRequest="130">
<ContentPresenter>
<ContentPresenter.Resources>
<Style TargetType="Label">
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="Center" />
<Style.Triggers>
<DataTrigger
Binding="{Binding Path=IsChecked, Source={x:RelativeSource AncestorType={x:Type RadioButton}}}"
TargetType="Label"
Value="True">
<Setter Property="TextColor" Value="{DynamicResource ColorText111}" />
<Setter Property="FontAttributes" Value="Bold" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContentPresenter.Resources>
</ContentPresenter>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CheckedStates">
<VisualState x:Name="Checked">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{DynamicResource ColorBack004}" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Unchecked">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{DynamicResource ColorBack000}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Frame>
</ControlTemplate>
</ContentPage.Resources>
<StackLayout
x:Name="xDispContents"
Grid.Row="9"
Grid.Column="1"
HorizontalOptions="StartAndExpand"
Orientation="Horizontal"
Spacing="0">
<Ctrl:CtrlRadioButton
x:Name="xBtnDisp_ABS"
ControlTemplate="{StaticResource FrameRadioTemplate}"
HorizontalOptions="Center"
VerticalOptions="Center">
<Ctrl:CtrlRadioButton.Content>
<!--<Label TextColor="{DynamicResource ColorText000}" />-->
<Ctrl:CtrlButton Text="ABS" />
</Ctrl:CtrlRadioButton.Content>
</Ctrl:CtrlRadioButton>
<Ctrl:CtrlRadioButton
x:Name="xBtnDisp_Trans"
ControlTemplate="{StaticResource FrameRadioTemplate}"
HorizontalOptions="Center"
VerticalOptions="Center">
<Ctrl:CtrlRadioButton.Content>
<Label Text="%T" TextColor="{DynamicResource ColorText000}" />
</Ctrl:CtrlRadioButton.Content>
</Ctrl:CtrlRadioButton>
</StackLayout>
I want to change the shape of the radio button, can I change the border size?
I'm trying to change the shape of a radio button's appearance using a control template. But I want to change the border thickness of the frame, but there is no way.
The default thickness is too thick. I've looked for many other examples, but there's no information about the thickness, so I'm asking.
Maybe you can use this , Frame in a Frame .
Change the Padding for the "BorderWith" Color.
<Frame HeightRequest="50" WidthRequest="100" BackgroundColor="Red" HorizontalOptions="Center" VerticalOptions="Start" Padding="0.7" IsClippedToBounds="True">
<Frame HeightRequest="50" WidthRequest="100" BackgroundColor="White" HorizontalOptions="Center" VerticalOptions="Start" Margin="0" Padding="0" IsClippedToBounds="True">
<Label Text="Padding 0.7" HorizontalOptions="Center" />
</Frame>
</Frame>
<Frame HeightRequest="50" WidthRequest="100" BackgroundColor="Red" HorizontalOptions="Center" VerticalOptions="Start" Padding="1" IsClippedToBounds="True">
<Frame HeightRequest="50" WidthRequest="100" BackgroundColor="White" HorizontalOptions="Center" VerticalOptions="Start" Margin="0" Padding="0" IsClippedToBounds="True">
<Label Text="Padding 1" HorizontalOptions="Center" />
</Frame>
</Frame>
<Frame HeightRequest="50" WidthRequest="100" BackgroundColor="Red" HorizontalOptions="Center" VerticalOptions="Start" Padding="5" IsClippedToBounds="True">
<Frame HeightRequest="50" WidthRequest="100" BackgroundColor="White" HorizontalOptions="Center" VerticalOptions="Start" Margin="0" Padding="0" IsClippedToBounds="True">
<Label Text="Padding 5" HorizontalOptions="Center" />
</Frame>
</Frame>
The result a border in Red in different size.

Xamarin Community Toolkit LongpressCommand stops item selection in CollectionView iOS

The code works as expected in Android but in iOS works inconsistently. The selected label's border changes colour when tapped, sometimes. After 3 or four taps of different labels they cease to be selected at all. Long pressing a label works as expected, opening a different view. On returning to the view containing the CollectionView code attached, label selection has been re-enabled. The process then repeats itself.
I've tried changing Nuget versions of both Xamarin.Forms and Xamarin.Community.Toolkit(even the latest pre-release), xaml and code-behind to no avail.
I'm at a loss. Any help would be appreciated.
<CollectionView x:Name="categoryCollectionView"
ItemsSource="{Binding Categories,Mode=TwoWay}"
SelectionMode="Single"
SelectedItem="{Binding Category}"
SelectionChanged="OnMenuItemSelected"
Grid.Column="0"
HorizontalOptions="FillAndExpand"
Grid.ColumnSpan="8"
Grid.Row="3"
VerticalScrollBarVisibility="Always" >
<CollectionView.ItemsLayout>
<GridItemsLayout x:Name="CategoriesGridLayout"
Orientation="Vertical"
Span="3"
VerticalItemSpacing="2"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="0">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Selected">
<VisualState.Setters>
<Setter TargetName="lblCategory" Property="Label.TextColor" Value="Red" />
<Setter Property="BackgroundColor" Value="Green" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<StackLayout Orientation="Vertical"
VerticalOptions="Center"
xct:TouchEffect.LongPressCommand="{Binding LongPressCategoryCommand, Source={RelativeSource AncestorType={x:Type vm:CategoryVM}}}"
xct:TouchEffect.LongPressCommandParameter="{Binding CategoryString}" >
<StackLayout.Margin>
<OnPlatform x:TypeArguments="Thickness" iOS="2,2,4,4" Android="2" />
</StackLayout.Margin>
<Label x:Name="lblCategory"
Text="{Binding CategoryString}"
FontSize="Small"
BackgroundColor="#f5e2e1"
VerticalOptions="Center"
HorizontalOptions="CenterAndExpand"
WidthRequest="350"
Padding="5"
TextColor="#232F34"
LineBreakMode="TailTruncation"
Style="{DynamicResource CategoryLabelStyle}" >
<Label.Triggers>
<DataTrigger TargetType="Label"
Binding="{Binding Source={x:Reference fontSizeSwitch}, Path=IsToggled}"
Value="true">
<Setter Property="FontSize"
Value="Medium" />
<Setter Property="Padding"
Value="2" />
</DataTrigger>
</Label.Triggers>
</Label>
</StackLayout>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>

Style button doesn't work inside the listbox

I create a usercontorl for listbox. User will go to different page by selecting the textbox inside the buttons. I must use the textbox because the contest need to wrap. I want to change the background color during the clicking. However, the button sytle doesn't work. Would someone can show me the example or link or hint to solve my problem.
The following is my style:
<UserControl.Resources>
<Style x:Key="btnCall" TargetType="Button" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard>
<DoubleAnimation To="1" Duration="0:00:00.5" Storyboard.TargetName="NormalBackground" Storyboard.TargetProperty="Opacity"/>
<DoubleAnimation To="0" Duration="0:00:00.5" Storyboard.TargetName="HoverBackground" Storyboard.TargetProperty="Opacity"/>
<DoubleAnimation To="0" Duration="0:00:00.1" Storyboard.TargetName="PressedBackground" Storyboard.TargetProperty="Opacity"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<DoubleAnimation To="0" Duration="0:00:00.5" Storyboard.TargetName="NormalBackground" Storyboard.TargetProperty="Opacity"/>
<DoubleAnimation To="0" Duration="0:00:00.5" Storyboard.TargetName="HoverBackground" Storyboard.TargetProperty="Opacity"/>
<DoubleAnimation To="1" Duration="0:00:00.1" Storyboard.TargetName="PressedBackground" Storyboard.TargetProperty="Opacity"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<!--<Border Name="NormalBackground" CornerRadius="3" BorderBrush="Fuchsia" BorderThickness="1" />-->
<Border x:Name="NormalBackground" BorderThickness="0" />
<Border x:Name="HoverBackground" Opacity="0" CornerRadius="3" BorderBrush="Yellow" BorderThickness="3" Background="Gray" />
<Border x:Name="PressedBackground" Opacity="0" CornerRadius="8" BorderBrush="Black" BorderThickness="1" Background="LightSteelBlue" />
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Left" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
I put the listbox in the grid as belows:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer Style="{StaticResource ScrollViewerStyle1}" Background="#00E23162">
<ListBox x:Name="lstCall" HorizontalAlignment="Left" Margin="6,6,0,0" VerticalAlignment="Top" Width="360" >
<ListBox.ItemTemplate>
<DataTemplate>
<Button Width="460" Height="70" Style="{StaticResource btnCall}" ClickMode="Press" Click="Detail_Click" >
<Button.Content >
<StackPanel Orientation="Horizontal" Height="65" Width="400">
<Image Source="{Binding Type}" Width="35" Height="35"/>
<TextBlock Width="240" Height="65" Text="{Binding summary}" TextWrapping="Wrap"
Style="{StaticResource PhoneTextAccentStyle}" />
<Button Width="135" Height="65" ClickMode="Press" Click="Action_Click" Style="{StaticResource btnCall}"
Visibility="{Binding isVisibility, Converter={StaticResource VisibilityConverter}}">
<Button.Content>
<TextBlock Width="200" Height="65" Text="{Binding ActionCaption}"
Style="{StaticResource LabelStyle_20}" />
</Button.Content>
</Button>
</StackPanel>
</Button.Content>
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
</Grid>

Allignment of controls in Datatemplate of listbox in silverlight

I need the following alignment
For that I have created the xaml file as follows,
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ListBox ItemsSource="{Binding Collections}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{Binding Icon}" HorizontalAlignment="Left" VerticalAlignment="Center" />
<Grid Grid.Column="1" HorizontalAlignment="Right" >
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="0.600*" />
<RowDefinition Height="0.400*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding MainTextBlock}" VerticalAlignment="Center" />
<Grid Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.300*" />
<ColumnDefinition Width="0.700*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Value}" HorizontalAlignment="Left" VerticalAlignment="Center" />
<TextBlock Grid.Column="1" Text="{Binding DateString}" HorizontalAlignment="Right" VerticalAlignment="Center" />
</Grid>
</Grid>
</Grid>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
but I did not get the as expected result. what should i do for that? sub2 is always left aligned but actually we need it to be Right aligned.
Thanks in advance
dinesh
I think the problem is with the nested grid elements that you're using in your DataTemplate. You can simplify the visual tree and achieve the desired results by using a single Grid that has the column and row definitions and then use the Grid.ColumnSpan and Grid.RowSpan attached properties as shown in the following XAML:
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="0.3*"/>
<ColumnDefinition Width="0.7*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0.6*"/>
<RowDefinition Height="0.4*"/>
</Grid.RowDefinitions>
<Image
Grid.RowSpan="2"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Source="{Binding Icon}"/>
<TextBlock
Grid.Column="1"
Grid.ColumnSpan="2"
Grid.Row="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding MainTextBlock}"/>
<TextBlock
Grid.Column="1"
Grid.Row="1"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{Binding Value}"/>
<TextBlock
Grid.Column="2"
Grid.Row="1"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Text="{Binding DateString}"/>
</Grid>
To achieve list box items that stretch the full width of the ListBox you need to add an ItemContainerStyle that sets the HorizontalContentAlignment to Stretch. You can create a copy of the default style in Expression Blend, or use the following:
<Style x:Key="FullWidthItemStyle" TargetType="ListBoxItem">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border
x:Name="LayoutRoot"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TransparentBrush}"/>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation
Duration="0"
Storyboard.TargetName="ContentContainer"
Storyboard.TargetProperty="Opacity"
To=".5"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentContainer" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneAccentBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentControl
x:Name="ContentContainer"
Margin="{TemplateBinding Padding}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Foreground="{TemplateBinding Foreground}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

How to set foreground color of ListBox item

I have a ListBox in a WP7 app page which I bind to a collection (List) of a custom object called Location. In that object is a field called WMO and what I want to do when the ListBox loads is set the foregound color of whatever bound listbox item has that same value as my default value... but I just can't seem to get this working and nothing I've read or googled has helped.
I know the items in the list are bound to the datasource but I want to get to the physical representation of that item and change the foreground colour.... just can't work out how I do that so if anyone can help I'd appreciate it.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0,0,0" >
<ScrollViewer Height="615" HorizontalAlignment="Left" Margin="5,5,5,5" Name="scrollViewer1" VerticalAlignment="Top">
<ListBox Name="lbxSavedLocs" Height="615" FontSize="22" HorizontalAlignment="Left" VerticalAlignment="Top" Width="470" SelectionChanged="lbxSavedLocs_SelectionChanged" Loaded="lbxSavedLocs_Loaded">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Width="380" Text="{Binding SiteName}" HorizontalAlignment="Left" />
<TextBlock Width="90" Text="{Binding WMO}" HorizontalAlignment="Center" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
</Grid>
private void lbxSavedLocs_Loaded(object sender, RoutedEventArgs e)
{
//Populate the listbox from our saved locations.
lbxSavedLocs.ItemsSource = gl.savedLocs.OrderBy(x => x.SiteName);
foreach (Location itm in lbxSavedLocs.Items)
{
if (loc.WMO == gl.defaultWMO)
{
//GET AN "INVALID CAST" EXCEPTION HERE:
((ListBoxItem)itm).Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
}
}
//Hopefully this produces a redraw of the ListBox.
lbxSavedLocs.InvalidateArrange();
}
Try this:
Option1:
ListBoxItem lbi1 = (ListBoxItem)(listBox.ItemContainerGenerator.ContainerFromIndex(0));
lbi1.Foreground= new SolidColorBrush(Color.FromArgb(100, 45, 23, 45));
Option2:
ListBoxItem lbi2 = (ListBoxItem)(listBox.ItemContainerGenerator.ContainerFromItem(listBox.Items.SelectedItem));
lbi2.Foreground= new SolidColorBrush(Colors.Red);
If you need to apply the same foreground colour to all items in the ListBox or to bind the foreground colour to a value in the data item, then the best approach is to modify the ItemContainerStyle. The ItemContainerStyle defines the visual wrapper around the contents of the ItemTemplate and by default uses a ContentControl that you can set or bind the Foreground property:
<Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border x:Name="LayoutRoot"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background"
Storyboard.TargetName="LayoutRoot">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TransparentBrush}"/>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation Duration="0"
To=".5"
Storyboard.TargetProperty="Opacity"
Storyboard.TargetName="ContentContainer"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentControl x:Name="ContentContainer"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
Foreground="#FFFF0000"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Background="Black"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Here is a way....i think it works
The property you want to bind is Foreground, so
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0,0,0" >
<ScrollViewer Height="615" HorizontalAlignment="Left" Margin="5,5,5,5" Name="scrollViewer1" VerticalAlignment="Top">
<ListBox Name="lbxSavedLocs" Height="615" FontSize="22" HorizontalAlignment="Left" VerticalAlignment="Top" Width="470" SelectionChanged="lbxSavedLocs_SelectionChanged" Loaded="lbxSavedLocs_Loaded">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Width="380" Text="{Binding SiteName}" Foreground="{binding forgroundColor}" HorizontalAlignment="Left" />
<TextBlock Width="90" Text="{Binding WMO}" Foreground="{binding forgroundColor}" HorizontalAlignment="Center" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
</Grid>
In the program put up the apt condition where you populate your listbox to choose the right Forground using foregroundColor
Populate the list box using a class containin
class lisboxItem
{
public string SiteName{get;set;}
public string forgroundColor{get;set;}
public string WMO{get;set;}
}
create a List<listboxItem> items=new List<listboxItem>();
and fill the list items in a loop where u give the condition you want.
after that
call
lbxSavedLocs.ItemSource=items

Resources