Reputation: 1467
In my view's xaml file, I have this line:
TextBox Text="{Binding MyModel.Text}"
Everytime I ran the program, it gave me this error message:
System.Windows.Data Error: 40 : BindingExpression path error: 'MyModel' property not found on 'object' ''MyModel' (HashCode=56593137)'. BindingExpression:Path=MyModel.Text; DataItem='MyModel' (HashCode=56593137); target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')
I'm sure my spelling is right.
I set my view's DataContext to ViewModel. Could that be a problem?
Upvotes: 1
Views: 86
Reputation: 5234
Since you're view is bound to your view-model (good), then your view-model needs to have a property that your view will bind to:
TextBox Text="{Binding MyViewModelsProperty}"
In your situation, you'll need to set your model's property from your view-model (MyViewModelsProperty setter).
Let me know if you need more info.
Upvotes: 0
Reputation: 26078
If your DataContext
is set to MyModel
you should just have to write:
<TextBox Text="{Binding Text}"/>
Adding the extra MyModel
is repetitive and results in looking for MyModel.MyModel.Text
.
Upvotes: 2