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 17:09] smayr |
swdev:dotnet:wpf:datatemplates [2012/12/07 17:15] (current) smayr [Example 2] |
||
---|---|---|---|
Line 83: | Line 83: | ||
Source: [[http:// | Source: [[http:// | ||
+ | === Example 1 === | ||
For a ListBoxItem: | For a ListBoxItem: | ||
<code xml> | <code xml> | ||
Line 96: | Line 97: | ||
</ | </ | ||
<code csharp> | <code csharp> | ||
+ | ListBoxItem lbi = (ListBoxItem)listBox.ItemContainerGenerator.ContainerFromIndex(IndexInListBox); | ||
ComboBox cb = (ComboBox)listBox.ItemTemplate.FindName(" | 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:// |