我有一个main.xaml文件。在main.xaml文件中,它指向另一个xaml文件中的列表框。这是使用视图调用:LayoutViewListwpf:绑定到另一个xaml文件中的控件
在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文件... – Kram
因为列表框控件有很多代码,所以它已被移动到另一个xaml文件。我如何从main.xaml访问列表框? – user3753452
好的。所以你需要创建一个可以获取数据的UserControl。然后,您可以重新使用您的客户usercontrol无论你想要 – Kram