xaml - unable to select listbox item through data template in WPF -


I am unable to select the desired item from the list box (when I click on any item in that list box, More than one item is selected but not the one I clicked on). Also changing the background color of the selected items to the default (white) color. The Xaml code I use is as follows:

  & lt; ListBox x: Uid = "lst_value" name = "lstValues" background = "wheat" BorderBrush = "black" horizontal alignment = "left" vertical alignment = "top" borderticiness = "1" height = "100" width = "150" = "{Bound list list}" & gt; & Lt; ListBox.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; StackPanel Orientation = "Vertical" Background = "Wheat" & gt; & Lt; TextBlock x: name = "txtblk" foreground = "black" fontisystem = "10" textilement = "left" fontweit = "black" text = "{binding}" background = "wheat" /> & Lt; / StackPanel & gt; & Lt; / DataTemplate & gt; & Lt; /ListBox.ItemTemplate> & Lt; / ListBox & gt;   

Can anyone tell me how to solve this issue?

You can also type Background to StackPanel and TextBlock , which obscures the selection, add resources to your ListBoxItems to override the background for selection.

  & lt; ListBox.ItemContainerStyle & gt; & Lt; Style TargetType = "ListBoxItem" & gt; & Lt; Style.Resources & gt; & Lt ;! - Selected brush - & gt; & Lt; Solid Coiler Brush X: Key = "{x: Static System Colors. Highlight Brush}" Color = "Green" /> & Lt ;! - selected but out of focus brush - & gt; & Lt; Solid Coiler Brush X: Key = "{x: Static System Colors. ControlBrisks}" Color = "LightGreen" /> & Lt; /Style.Resources> & Lt ;! If you want to set the background, then do it here, though there should be redundancy in the form of listboxes. Background is similar - & gt; & Lt; Setter property = "background" value = "wheat" /> & Lt; / Style & gt; & Lt; /ListBox.ItemContainerStyle>   

If you have a source archive with the same objects (such as strings that have the same values), the selection problem may appear.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -