【发布时间】:2013-06-13 15:26:52
【问题描述】:
我想绑定到从位于ResourceDictionary 中的DataTemplate 动态插入到我的窗口中的元素属性(在我的特定情况下是ListBox 的SelectedItems.Count)。当计数达到一定数量的ListBoxItems 被选中时,我想启用/禁用一个按钮。我认为这会起作用:
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding Source={StaticResource myResourceKey}, Path=myListBox.SelectedItems.Count}" Value="25">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
但我收到以下错误:
System.Windows.Data Error: 40 : BindingExpression path error: 'myListBox' property not found on 'object' ''DataTemplate' (HashCode=50217655)'. BindingExpression:Path=aoiListBox.SelectedItems.Count; DataItem='DataTemplate' (HashCode=50217655); target element is 'Button' (Name='myBtn'); target property is 'NoTarget' (type 'Object')
我怎样才能实现这种绑定?提前致谢。
【问题讨论】:
标签: wpf binding datatemplate resourcedictionary