0
private MyObject _myObject; public MyObject MyObject { get { return _myObject; } set { if (_myObject != value) { _myObject = value; RaisePropertyChanged(() => MyObject); } } } <TextBox Text="{Binding MyObject.MyObjectProperty}"/> 

When starting my app, MyObject is initialized, the MyObjectProperty is shown in my TextBox, but when I change the MyObjectProperty of MyObject, the TextBox is not updated!

5
  • 2
    Does your MyObject also raise property changed notifications? Commented May 29, 2013 at 12:44
  • Do you mean if MyObject also implements INotifyPropertyChanged? If yes the answer is no, MyObject is a Model object, only my ViewModels implement the INotifyPropertyChanged. Commented May 29, 2013 at 12:48
  • To make your code work, you need to implement INotifyPropertyChanged on MyObject as well - refer to @blindmeis answer Commented May 29, 2013 at 12:57
  • 1
    If your posted code is accurate then you've missed something: your binding doesn't match your property name (MyObjectProperty vs MyObject). Which is it and what else have you missed? Commented May 29, 2013 at 13:00
  • try the '_myObject = value;' before the if-operator in your property. sometimes it's working, then there is something wrong :D Commented May 29, 2013 at 13:01

2 Answers 2

1

does your MyObject object implement INotifyPropertyChanged and call it?

public class MyObject { private string _prop; public string MyObjectProperty { get { return _prop; } set { if (_prop!= value) { _prop = value; RaisePropertyChanged(() => MyObjectProperty); } } } } 

and the default UpdateSourceTrigger is LostFocus so you have to leave the textbox to see anything

Sign up to request clarification or add additional context in comments.

Comments

0

In addition to what blindmeis said, make sure you also specify two way binding on the textbox.

<TextBox Text="{Binding Path=MyObject.MyProperty, Mode=TwoWay"}/> 

2 Comments

You don't need it, Controls like TextBox have default TwoWay mode.
@Stacked - Good point and that is true for WPF. Silverlight, on the other hand, does not default it. I always forget which settings apply to which technology. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.