我有一个嵌套ItemsControl
显示以下模型:
public class Parent
{
public string ParentTitle
{
get;
set;
}
ICollection<Child> Children
{
get;
set;
}
}
public class Child
{
public string ChildTitle
{
get;
set;
}
}
ItemsControl
看起来像这样:
<ItemsControl x:Name="listOfParents">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:Parent}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button x:Name="btnTarget" Grid.Row="0" Content="{Binding ParentTitle}"></Button>
<ItemsControl Grid.Row="1" ItemsSource="{Binding Children}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:Child}">
<Button x:Name="btnSource" Content="{Binding ChildTitle}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
listOfParents Itemssouce是List<Parent>
. Button
单击btnSource时如何访问btnTarget?