I am unable to select desired item from the listbox
(when i click on any item in that listbox the items more than one are getting selected but not the one on which i have clicked). Also the background color of the selected items are getting changed to default (white) color.
The Xaml code used by me is as follows:
<ListBox x:Uid="lst_value" Name="lstValues" Background="Wheat"
BorderBrush="Black" HorizontalAlignment="Left" VerticalAlignment="Top"
BorderThickness="1" Height="100" Width="150" ItemsSource="{Binding listval}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Background="Wheat">
<TextBlock x:Name="txtblk" Foreground="Black" FontSize="10"
TextAlignment="Left" FontWeight="Black" Text="{Binding}"
Background="Wheat"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Could anyone let me know how to resolve the issue please.
You should not set the
Backgroundon theStackPanelandTextBlock, that obfuscates the selection. To override the background for the selection add resources to your ListBoxItems.The selection issue can appear if you have a source collection with identical objects (like strings that have the same value).