I saw something about this, but I've lost it now, and can't find it again. What I need is to know which ListViewItem a checkbox exists in, when the checkbox is checked (Which will eventually lead to its deletion),
I tried getting the parent, but apparently that doesn't work.
XAML:
<ListView Name="incomingMessages" Extensions:ListViewColumns.Stretch="true" Height="226" Canvas.Left="0" Canvas.Top="0" Width="755" ItemsSource="{Binding Messages}"> <ListView.View> <GridView> <GridViewColumn Header="Time" Width="100" DisplayMemberBinding="{Binding Time}" /> <GridViewColumn Header="Message" DisplayMemberBinding="{Binding FullMessage}" /> <GridViewColumn Header="Phone Number" DisplayMemberBinding="{Binding Number}" Width="85" /> <GridViewColumn Header="Done" Width="45"> <GridViewColumn.CellTemplate> <DataTemplate> <CheckBox IsChecked="{Binding Done}" VerticalAlignment="Center" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView>
What sort of code needs to go in the Checked event to make it work? (As a side question, why does my VerticalAlignment not center align my checkboxes in the column?)
Like I said I tried parent in this sort of code
private void CheckBox_Checked(object sender, RoutedEventArgs e) { CheckBox cb = (CheckBox)sender; object lv = cb.parent; }
And if I breakpoint on the cb.parent line, cb.parent is null.
Thanks, Psy