当前位置:首页 > Windows程序 > 正文

including the WPF Window

2024-03-31 Windows程序

技术分享图片

main window预览:

Model: 

技术分享图片

技术分享图片

view model1:

技术分享图片

viewmodel2: CustomerInfoViewModel

技术分享图片

此中上方缩小部分的代码如下:

技术分享图片

创建一个view:  CustomeInfoView

技术分享图片

技术分享图片

看一下父子窗体:

技术分享图片

疑问:DataContext指的是?

The DataContext property is the default source of your bindings, unless you specifically declare another source, like we did in the previous chapter with the ElementName property. It‘s defined on the FrameworkElement class, which most UI controls, including the WPF Window, inherits from. Simply put, it allows you to specify a basis for your bindings

There‘s no default source for the DataContext property (it‘s simply null from the start), but since a DataContext is inherited down through the control hierarchy, you can set a DataContext for the Window itself and then use it throughout all of the child controls. Let‘s try illustrating that with a simple example:

技术分享图片

如果将childviewmodel.Info文字变动成如下逻辑,,效果:

技术分享图片

我们也可以将viewmodel拓展成属性property.

技术分享图片

设置为public的话,外部也可以挪用了。

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/34582.html

Jm-杰米博客Jamie
草根站长的技术交流乐园!IT不会不要紧快来好好学习吧!
  • 20786文章总数
  • 7494589访问次数
  • 建站天数
  • 友情链接