WPF: ListView inside LIstViewItem: How to support button_click
- by Bartek
Hi
I have problem with using buttons that are placed in the itemtemplate of the listview which is placed in the itemtemplate of the outer listview. I'll try to simplify the code to show only the idea.
I have a objects collection which looks like this: Main object contains a list of innerObjects. Every innerObject contains a list of objects that contain some strings.
mainObject
listItem
innerListItem
string
string
innerListItem
string
string
listItem
innerListItem
string
string
I set a mainObject as a itemsSource to the ListView. This listView has a ItemTemplate. This ItemTemplate contains some buttons and inner ListView. Inner ListView also has the item template that contains a button (deleteButton). Pressing this deleteButton I want to delete items (innerListItem) for which this button was created.
I can use such functionality when I have a sigle listView.
private void clearAndList_Click(object sender, RoutedEventArgs e)
{
DependencyObject dep = (DependencyObject)e.OriginalSource;
while ((dep != null) && !(dep is System.Windows.Controls.ListViewItem))
{
dep = VisualTreeHelper.GetParent(dep);
}
if (dep == null)
{
return;
}
ANDconditionsList andList = (ANDconditionsList)ConditionsList.ItemContainerGenerator.ItemFromContainer(dep);
orConditionsList.RemoveConditionsSet(andList);
}
I can't use the same functionality because I can only use the name of the ConditionsList which is the mail listview. The idea is to find the innerlistview and use it instead of ConditionsList, however I don't know if it will work. If anyone have some samples concerning using listview in listview or how to operate the button in a different way please help me