【发布时间】:2017-12-05 21:26:10
【问题描述】:
我有一个具有 AllowDrop 属性的模型类 ViewItem。我的视图模型 ViewModel 是 ViewItem 的可观察集合。
ViewItem 属性
public bool AllowDrop
{
get
{
return _allowDrop;
}
}
我有一个 ViewTree,它的数据源绑定到 ViewModel 的一个实例 MyItems。
我希望能够访问将 ViewTreeItems AllowDrop 属性绑定到底层模型,但是我不知道访问它的正确方法。
我的 TreeView XAML 看起来像这样
<TreeView x:Name="ViewsTree"
AllowDragDrop="True"
DragOver="ViewsTree_DragOver"
ItemsSource="{Binding MyItems}"
ItemTemplate="{StaticResource ViewTemplate}"
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="AllowDrop" Value="{Binding}"/>
</Style>
</TreeView>
我不知道如何访问 MyView 集合中的 ViewItem 以绑定到 AllowDrop 属性。
【问题讨论】:
-
您的问题太模糊,无法回答。它不包括minimal reproducible example,但更关键的是,根本不清楚数据中找到的多个值为何以及如何映射到视图中的一个单个值。如果不是所有的视图项
AllowDrop属性都具有相同的值,您期望会发生什么。无论您期望什么,为什么您认为这是一个合适的选择?在我看来,将属性放在容器视图模型对象中更有意义,该对象引用项目集合和单个属性。