WPF中的区域如何没有棱镜?

编程入门 行业动态 更新时间:2024-10-28 15:30:16
本文介绍了WPF中的区域如何没有棱镜?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

特别是在MVVM Light工具包中吗?我还没有深入研究Prism代码,以了解它对WPF UI中的区域有何作用.就像在MVVM Light中使用消息传递和ViewModelLocator一样,您可以做类似的事情....可以吗?谁能举一些例子说明如何做到这一点?本质上,我想单击一个按钮,然后将两个不同的视图模型加载到UI中.也许更好的解释方法是类似Outlook的导航窗格功能.

Specifically in MVVM Light toolkit? I've not dove into the Prism code yet to see what it does in regard to regions in a WPF UI. Seems like with the messaging and the ViewModelLocator in MVVM Light you could do a similar thing....Can you? Can anyone give some examples on how you could do this? Essentially I'd like to click on a button and load two different view models into the UI. Perhaps a better way to explain is Outlook-like Navigation Pane functionality.

推荐答案

在WPF中,无需任何框架即可轻松完成此操作.

This can be done fairly easily in WPF, without any framework.

只需在应用程序(或应用程序中)中设置 DataTemplate Window/UserControl级别),将ViewModel映射到您希望为该ViewModel显示的视图.

Just setup a DataTemplate in your Application (or at the Window/UserControl level) that maps the ViewModel to the View you wish to display for that ViewModel.

然后,您可以只使用 ContentPresenter ,并将其内容绑定到ViewModel中的单个属性(可以是object类型).当您要将区域"设置为特定的View时,只需将属性设置为适当的ViewModel,WPF就会自动为您连接所有内容.

You can then just use a ContentPresenter, and bind it's contents to a single property (which can be of type object) within your ViewModel. When you want to set the "region" to a specific View, just set the property to the appropriate ViewModel, and WPF will automatically wire up everything for you.

更多推荐

WPF中的区域如何没有棱镜?

本文发布于:2023-11-06 14:56:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564003.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:棱镜   区域   WPF

发布评论

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

>www.elefans.com

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