About a month ago, I saw two unrelated questions where an ItemsControl was not behaving correctly when clicking on an item: Events weren’t being raised, items weren’t getting selected; chaos ensued. In both cases, the developer was adding an items container to the data template. (As a refresher, ListBoxItem, ListViewItem, and TreeViewItem are examples of item containers.) They were doing something like the following: < Grid > < Grid.Resources > < src : ItemsForSale x : Key ="Data"/> </ Grid.Resources > < ListBox ItemsSource ="{ StaticResource Data }"> < ListBox.ItemTemplate > < DataTemplate > < ListBoxItem Padding ="3,8,3,8" MouseDoubleClick ="ListBoxItem_MouseDoubleClick" > < TextBlock Text ="{ Binding Path =Description}"/> </ ListBoxItem > </ DataTemplate > </ ListBox.ItemTemplate > </ ListBox > </ Grid > When the correct way to implement the ListBox is something like the following: < Grid > <
Read More...