我知道有一堆像这样的其他类似的SO帖子,但似乎没有我的场景,我绑定到一个类属性,AND其他属性工作正好。我正在使用MVVM模式,其中我的viewmodel在C++/cli。由于其他属性起作用,它不是我的视图的DataContext
。我有一个IsEnabled
Button
绑定到我的ViewModel中的布尔。现在,当试图绑定到类似的东西,WPF绑定到类属性的错误,当其他属性工作正常
private:
bool thing = false;
public:
bool Thing
{
bool get() { return thing; }
void set(bool value) { thing = value; }
}
它工作得很好。但后来我做这样的事情,
public ref class MyThingClass
{
private:
bool isEnabled = false;
public:
bool IsEnabled
{
bool get() { return thing; }
void set(bool value) { thing = value; }
};
};
public:
//Not sure if I need a handle (^) on this or not
MyThingClass MyThing;
//XAML
<Button x:Name="MyButton" IsEnabled="{Binding MyThing.IsEnabled}"/>
决定的东西打破,属性不绑定,并在输出我得到System.Windows.Data Error: 40 : BindingExpression path error: 'MyThing ' property not found on 'object' ''MyViewModel' (HashCode=66641179)'. BindingExpression:Path=MyThing.IsEnabled; DataItem='MyViewModel' (HashCode=66641179); target element is 'Button' (Name='MyButton'); target property is 'IsEnabled' (type 'Boolean')
请提问,如果我留下什么东西了,或者说没有按”没有意义。
好吧,显然我需要改变我的问题。我的ViewModel实际上是在C++/CLI中,所以这种方法不能直观地移植。我真的很抱歉改变了事情,我认为事情会变得更好,而且C#更易于编写/读取。 –
@SanjayCruze我会关闭/接受它,并提出一个新的问题,显示实际的代码(或者至少在C++/CLI中的代码) –
嗯,只是改变它。我是否应该改回它,接受这个答案,并提出一个新的问题? –