Reputation: 938
How can I change selected item's background color that in listbox which has datatemplate in Windows Phone?
I have seen that it can be with Setter Properties. Where I will write them?
Thanks.
Code
<ListBox x:Name="listLocs" HorizontalAlignment="Left" Height="605" VerticalAlignment="Top" Width="250" SelectionChanged="listLocs_SelectionChanged" Margin="10,155,0,0" BorderBrush="#FF030042" BorderThickness="2" Foreground="#FF030042">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel>
<Image Source="/Images/Pin2.png" Width="60" Height="60" />
</StackPanel>
<StackPanel>
<StackPanel>
<TextBlock x:Name="txtName" Margin="10,0,0,0" Foreground="#FF030042" FontSize="30" Text="{Binding Name}"/>
</StackPanel>
<StackPanel>
<TextBlock x:Name="txtDescription" Margin="10,0,0,0" Foreground="#FF030042" FontSize="20" Text="{Binding Description}"/>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Upvotes: 0
Views: 4069
Reputation: 560
You can do that in code behind altough in selectchanged event handler:
private void listLocs_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBoxItem myitem = listLocs.SelectedItem as ListBoxItem;
SolidColorBrush brush = new SolidColorBrush(Color.FromArgb(255,255,0,0));
myitem.Background = brush;
}
Upvotes: 1