更改主查看区域
我想知道按下按钮时如何在主窗口中创建不同的视图。我不确定正确的术语,所以这阻碍了我的谷歌搜索。
我认为主要查看区域将是内容控件,当事件发生时我可以更改它。我画了一张小图来帮助说明我的想法/想法。
任何意见将不胜感激。谢谢!
I'm wondering how to go about creating different views in the main window when a button is pressed. I'm not sure of the correct terminology, so that has hampered my google fu.
I'm thinking that the main viewing area would be a content control, that I could change when a event happens. I made a small drawing to help illustrate my idea / thought.
Any input will be appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 MVVM 方法实现这个场景真的很容易......
为你的 MainView 创建一个 ViewModel。然后定义 UserControls 的 ViewModel 的属性
例如,您有两个 UserControl 作为 FirstView 和 SecondView 然后在视图模型中将属性设置为 ViewToLoadProperty 的ViewModel 类型(通常称为 ViewModelBase)
将绑定设置为
然后当您单击按钮时使用命令将相应的 ViewModel 实例设置为此(ViewToLoadProperty)属性...(使用
RelayCommannds
或类似的东西)DataTempates
将通过根据正确的 ViewModel 类型选择正确的视图来完成其余的工作,如果您正在实现 MVVM,则可以使用 MVVMLight 工具包图案.. :)
It would be really easy to implement this senario using MVVM approach....
Make a ViewModel for you MainView. Then Define Properties of the ViewModels of your UserControls
For Example You have Two UserControl as
FirstView
andSecondView
then make a properties in your viewmodels asViewToLoadProperty
of the type ViewModel (usually called as ViewModelBase)Set bindings as
Then when you click the button Use a command to set the respective ViewModel Intance to this(ViewToLoadProperty) property...(Use
RelayCommannds
or something like it)DataTempates
would do the rest of the job by selecting the right View according to the right type of ViewModelYOu can use MVVMLight toolkit if you are implementing MVVM Pattern.. :)
右边你可以有一个框架。然后该按钮会将不同的页面或用户控件绑定到该框架的内容。
On the right you could have a frame. Then the button would bind a different page or user control to the content of that frame.