【发布时间】:2015-06-25 12:02:36
【问题描述】:
我有一个 main.xaml 文件。在 main.xaml 文件中,它引用另一个 xaml 文件中的列表框。它是使用 view:LayoutViewList 调用的
在 main.xaml 文件中,有一个按钮。该按钮仅在选择列表框时启用。看起来 ElementName=view.LayoutViewList.LayoutListBox 不起作用。非常感谢
Button IsEnabled="{Binding ElementName=view:LayoutViewList.LayoutListBox, Path=SelectedItems.Count}"
绑定错误:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=view:LayoutViewList.LayoutListBox'. BindingExpression:Path=SelectedItems.Count; DataItem=null; target element is 'Button' (Name=''); target property is 'IsEnabled' (type 'Boolean')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=view:LayoutViewList.LayoutListBox'. BindingExpression:Path=SelectedIndex; DataItem=null; target element is 'Button' (Name=''); target property is 'NoTarget' (type 'Object')
【问题讨论】:
-
为什么两个 xaml 不使用相同的列表?我不确定您是否可以引用另一个 xaml 文件...
-
因为listbox控件的代码很多,所以移到了另一个xaml文件中。如何从 main.xaml 访问列表框?
-
好的。因此,您需要创建一个将获取数据的 UserControl。然后您可以在任何地方重复使用您的客户用户控件