[英]Binding to UserControl property
I have an UserControl property in the presenter: 我在演示者中有一个UserControl属性:
public UserControl Control { get; set; }
The XAML code: XAML代码:
<ContentControl Content="{Binding Control}"/>
When I run the application I get this error: 当我运行应用程序时,出现以下错误:
System.Windows.Data Error: 40 : BindingExpression path error: 'Presenters' property not found on 'object' ''MainPresentet' (HashCode=24706823)'.
System.Windows.Data错误:40:BindingExpression路径错误:在“对象”“ MainPresentet”(HashCode = 24706823)上找不到“ Presenters”属性。 BindingExpression: Path=Presenters;
BindingExpression:路径=演示者; DataItem='MainPresenter' (HashCode=24706823);
DataItem ='MainPresenter'(HashCode = 24706823); target element is 'ItemsControl' (Name=' ');
目标元素是'ItemsControl'(Name =''); target property is 'ItemSource' (type 'IEnumerable')
目标属性为“ ItemSource”(类型为“ IEnumerable”)
I tried to change the property to IEnumerable and use ItemsControl and I got same error. 我试图将属性更改为IEnumerable并使用ItemsControl,但遇到了相同的错误。
I dont know the name of the UserControl because I get him from other dll in runtime 我不知道UserControl的名称,因为我是在运行时从其他dll中获得的
Your error is pretty clear: 您的错误非常清楚:
System.Windows.Data Error: 40 : BindingExpression path error: 'Presenters' property not found on 'object' ''MainPresentet' (HashCode=24706823)'.
System.Windows.Data错误:40:BindingExpression路径错误:在“对象”“ MainPresentet”(HashCode = 24706823)上找不到“ Presenters”属性。 BindingExpression: Path=Presenters;
BindingExpression:路径=演示者; DataItem='MainPresenter' (HashCode=24706823);
DataItem ='MainPresenter'(HashCode = 24706823); target element is 'ItemsControl' (Name=' ');
目标元素是'ItemsControl'(Name =''); target property is 'ItemSource' (type 'IEnumerable')
目标属性为“ ItemSource”(类型为“ IEnumerable”)
This means that somewhere in your code, you have tried to data bind to a property named Presenters
, but that the DataContext
where you tried that is actually set to an object of type MainPresenter
and this object does not have a public Presenters
property declared in it. 这意味着您在代码中的某处尝试将数据绑定到名为
Presenters
的属性,但是将您尝试过的DataContext
实际设置为MainPresenter
类型的对象,并且此对象中没有声明公共的Presenters
属性。 。 This Binding
was set on an ItemSource
property of an ItemsControl
, or derived class, like a ListBox
. 此
Binding
是在ItemsControl
或派生类(如ListBox
的ItemSource
属性上设置的。
Therefore, this error has nothing to do with your displayed code and you will need to search your code for the Presenters
Binding Path
and fix that Binding
. 因此,此错误与您显示的代码无关,您将需要在代码中搜索
Presenters
Binding Path
并修复该Binding
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.