Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit ListBox and ItemTemplate
2 replies. Latest Post by y_makram on December 2, 2008.
(0)
novy
Member
2 points
17 Posts
12-02-2008 3:52 AM |
Here is some code <ListBox x:Name="lstRaporty" SelectionChanged="lstRaporty_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate> <CheckBox IsChecked="{Binding Path=IsChecked, Mode=TwoWay}" Content="{Binding Path=Name}" Click="CheckBox_Click" Margin="0,5,0,5" /> </DataTemplate> </ListBox.ItemTemplate></ListBox>When I click checkbox on the list the only "Click" event is raised and I have no information which item belongs to clicked checkbox because "SelectionChanged" event is not raised.
silverbyte
Participant
1338 points
405 Posts
12-02-2008 3:59 AM |
Suppose your bounded class object is called MyClass
void CheckBox_Click(sender, e)
{
MyClass myObj = (sender as CheckBox).DataContext as MyClass;
string name = myObj.Name;
}
y_makram
Contributor
6172 points
1,233 Posts
12-02-2008 4:05 AM |
THis is because clicking on the CheckBox will not even select the item. I have written the following code as a workaround:
private void CheckBox_Click(object sender, RoutedEventArgs e) { sender.ToString(); CheckBox c = sender as CheckBox; int index = 0; foreach (company item in lstRaporty.Items) { if (item.Name == c.Content.ToString()) lstRaporty.SelectedIndex = index; index++; } }