views:

201

answers:

1

I have a parent object of type Parent and it currently has a null property called Foo of type Child and that Child class has a property of type string called Name.

If the user types into a Text Box for that Name property then I want to automatically create an instance of Child and set it as the Foo property of Parent before finally setting the Name property of the Child object.

If i use:

{Binding parent.foo.name, Mode=TwoWay}

It doesn't create foo and essentially does nothing. Is there any way to achieve what I want without pre-creating all the possible child objects and then removing them if properties haven't been set?

A: 

There is no automatic way. You could consider using a pattern like M-V-VM and handling this logic in the ViewModel. You might also possibly get creative with an IValueConverter so that your binding can run custom code when the value is set. But WPF / Silverlight binding will not automatically do this work for you.

Jared Bienz - MSFT