Push DependencyProperty back to ViewModel upon DataContext Change

I dont know if I have some kind of design flaw in what I am writing but im a little stuck as to the approach I am currently trying to use.

I have a case in my ViewModel where I want to do clamping on certain values based on the current state of the user-control. For this to work, I need to bind to properties on that control and ensure that the ViewModel always knows about its current state.

In one instance, this works great. If a value changes on the control, the DependencyProperty of the View says, hey, ive changed. And the data is pushed to my ViewModel. Brilliant!

The problem arises when my ViewModel is switched out, and the View doesn't change. A great example of this would be the View's ActualWidth and ActualHeight. Upon a ViewModel switch (effectively removing the old one, and reinstantiating a new one). The DependencyPropertys will not change. Thus my new view model never recieves the data of the view.

This means that somehow my Control MUST know when its ViewModel changes. Right?

If this all makes sense, how do I go about "pushing" the new values to my view model. Even if they haven't changed?

链接地址: http://www.djcxy.com/p/50472.html

上一篇: 即使使用单向模式设置也只有财产

下一篇: 在DataContext更改时将DependencyProperty推回到ViewModel