Welcome to Windows Presentation Foundation (WPF)
Top Tasks :

WPF Team Bloggers

ItemControls don’t properly select items or raise events when bound to a data source

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...
Published Sunday, April 27, 2008 1:49 PM by Windows Presentation Foundation SDK

Comments

No Comments
Anonymous comments are disabled

Copyright © 2006 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us