views:

26

answers:

1

I have WPF window which binds a local Dependency property to a property of my usercontrol. So now I see the value which the window gave me in my usercontrol. I achieve this by setting DataContext of window to the window itself

Now once the window is loaded i set the DataContext of usercontrol to a ViewModel class, and at some point of time(based on user action) the control changes values in the control. All fine so far.

But now the changed value is not reflected in Windows dependency property. How I can resolve this issue?

+1  A: 

Why do you need a DP in your window? Just databind the property of the user control to the corresponding property in your WM. If the usercontrol should be able to update the property in the VM you need to use two way binding and the property in the VM need a public set property.

Here's an example: http://stackoverflow.com/questions/2921926/change-binding-value-not-binding-itself/2924244#2924244

Wallstreet Programmer
I need DP in the window because I need some way to provide initial state to the user control. Also there are scenarios where some other user control is bound to the value of this user control.
Nitin Chaudhari
Did you check the link? It initializes the user control's DP to Brushes.Red. If you want to bind a property of a user control to another you can do that directly in xaml, you don't need a DP in some window for that: <Slider Name="_slider" /> <TextBlock Text="{Binding Path=Value, ElementName=_slider}" />
Wallstreet Programmer