数据绑定说明(Databinding explanation)

编程入门 行业动态 更新时间:2024-10-26 14:38:41
数据绑定说明(Databinding explanation)

我尝试了以下答案:

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.

更多推荐

本文发布于:2023-08-07 18:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465505.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   数据   explanation   Databinding

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!