Pushing read-only GUI properties back into ViewModel

后端 未结 6 1911
攒了一身酷
攒了一身酷 2020-11-22 12:50

I want to write a ViewModel that always knows the current state of some read-only dependency properties from the View.

Specifically, my GUI contains a FlowDocumentPa

6条回答
  •  广开言路
    2020-11-22 13:30

    Here is another solution to this "bug" which I blogged about here:
    OneWayToSource Binding for ReadOnly Dependency Property

    It works by using two Dependency Properties, Listener and Mirror. Listener is bound OneWay to the TargetProperty and in the PropertyChangedCallback it updates the Mirror property which is bound OneWayToSource to whatever was specified in the Binding. I call it PushBinding and it can be set on any read-only Dependency Property like this

    
        
            
            
        
    
    

    Download Demo Project Here.
    It contains source code and short sample usage.

    One last note, since .NET 4.0 we are even further away from built-in-support for this, since a OneWayToSource Binding reads the value back from the Source after it has updated it

提交回复
热议问题