Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
swdev:dotnet:wpf:datatemplates [2012/12/07 16:59] smayr |
swdev:dotnet:wpf:datatemplates [2012/12/07 17:15] (current) smayr [Example 2] |
||
---|---|---|---|
Line 82: | Line 82: | ||
</ | </ | ||
Source: [[http:// | Source: [[http:// | ||
+ | |||
+ | === Example 1 === | ||
+ | For a ListBoxItem: | ||
+ | <code xml> | ||
+ | <ListBox Name=" | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | <code csharp> | ||
+ | ListBoxItem lbi = (ListBoxItem)listBox.ItemContainerGenerator.ContainerFromIndex(IndexInListBox); | ||
+ | ComboBox cb = (ComboBox)listBox.ItemTemplate.FindName(" | ||
+ | </ | ||
+ | |||
+ | === Example 2 === | ||
+ | For a ListBoxItem: | ||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | . . . | ||
+ | <ListBox ItemsSource=" | ||
+ | </ | ||
+ | |||
+ | <code csharp> | ||
+ | // To get GreekGod object | ||
+ | GreekGod greekGod = (GreekGod)(listBox.Items[0]); | ||
+ | |||
+ | // To get ListBoxItem container holding object GreekGod | ||
+ | ListBoxItem lbi1 = (ListBoxItem)(listBox.ItemContainerGenerator.ContainerFromIndex(0)); | ||
+ | ListBoxItem lbi2 = (ListBoxItem)(listBox.ItemContainerGenerator.ContainerFromItem(listBox.Items.CurrentItem)); | ||
+ | </ | ||
+ | |||
+ | Source: [[http:// |