Databinding problem with null object RRS feed

  • Question

  • Suppose I have VM, and UI control MyForm which DataContext is MyV.

    MyVM has one property Address(AddressLine, City, .....), and another property Name

    In MyForm, there are many Textbox to bind to the each data field. like

    <TextBox Text="{Binding AddressLine, Mode=TwoWay}"  />

    If I have instance of myVM with a non-null instance Address, everything is fine.

    But if I have a instance of MyVM like new MyVM("MyName"). Address is null(never assigned), then bind this VM to myForm.

    If user input something in AddressLine, system can't create an Address instance in myVM even INotifyPropertyChanged implemented.

    What's the best solution for this case? (this is happen when you populate data from database to VM).

    Thursday, September 2, 2010 1:46 PM


  • the constructor that takes in just a name should probably initialize the Address property to have all empty strings instead of just leaving it null.

    Thursday, September 2, 2010 3:10 PM