我尝试了以下答案:
https://stackoverflow.com/a/16947081/2111258
我已经得到了代码,但我不明白dockpanel中的滑块如何绑定ScaleFactor属性。 使用断点我发现它绑定到MainWindow的ViewModel对象。
绑定定义“{Binding ScaleFactor}”如何将其绑定到属于MainWindow的完全不同的对象的属性?
i tried out the following answer:
https://stackoverflow.com/a/16947081/2111258
I have gotten the code to work, but I dont understand how the slider in the dockpanel has the ScaleFactor property bound. Using breakpoints i found out that its bound to the MainWindow's ViewModel object.
How does the bind definition "{Binding ScaleFactor}" bind it to the property of a completely different object belonging to the MainWindow?
最满意答案
也许我错过了一些东西,但我没有看到任何异常。
绑定视图的对象在DataContext属性中指定:
DataContext = ViewModel = new PanZoomViewModel();PanZoomViewModel包含ScaleFactor属性,该值在UI中更改时由视图读取和更新。 当它在代码中被更改时,它的setter会触发OnPropertyChanged事件,因此视图知道它应该更新相应的UI元素。
Maybe I am missing something but I don't see anything unusual there.
Object the view is bound to is specified in DataContext property:
DataContext = ViewModel = new PanZoomViewModel();PanZoomViewModel contains ScaleFactor property which value is read and updated by view when changed in UI. And when it is changed in code its setter fires OnPropertyChanged event, so view knows it should update corresponding UI element.
更多推荐
发布评论