将 TreeView 中 ChildButton 的标记属性绑定Tag="{Binding ParentData}"到类 TreeParent 的 ParentData 属性的最佳方法是什么?
<TreeView>
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:TreeParent}" ItemsSource="{Binding Members}">
<Button x:Name="ParentButton" Text="{Binding ParentName}">
</Button>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type local:TreeChild}" ItemsSource="{Binding Members}">
<Button x:Name="ChildButton" Text="{Binding ChildName}" Tag="{Binding ParentData}">
</Button>
</DataTemplate>
</TreeView.Resources>
</TreeView>
xaml 文件后面的 .cs 代码如下所示:
public class TreeParent
{
public string ParentName { get; set; }
public SomeDataClass ParentData { get; set; }
public ObservableCollection<TreeChild> Members { get; set; }
}
public class TreeChild
{
public string ChildName { get; set; }
}
当年话下
相关分类