将视图注入容器 MVVM WPF
这让我痛苦了一段时间。
我知道 Prism 将视图注入区域,但是有没有办法在视图优先的基础上用 Cinch 做类似的事情?例如,我有一个容器(实际上是一个区域),它可以在运行时包含任何视图 - 我并不特别想在 XAML 中显式设置视图,因为这会加载它,而且有点混乱。有一个容器可以用来做这个吗?我该怎么办呢? (不必是 Cinch 特定的..)
谢谢。
This has been giving me pain for some time.
I know Prism injects views into regions, however is there a way of doing a similar sort of thing with Cinch, on a view first basis? For example I have a container (effectively a region) which can contain any view at runtime - I don't particularly want to set the view explicitly in XAML as this will load it up, and it's a bit messy. Is there a container that I can use for this? And how would I go about it? (doesn't have to be Cinch specific..)
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了回答我自己的问题,我发现 Prism v4 提供了一个有用的解决方案 - 一个名为 RequestNavigate 的 RegionExtension。
我已经使用 RequestNavigate 打开一个新窗口(查看 StockTrader RI),但是如果遵循正确的 MVVM 方法,这似乎非常麻烦。相反,我决定使用 WPF 扩展工具包中的 ChildWindow 类,您可以在其中纯粹绑定到“WindowState”(打开/关闭)属性,并在 XAML 中指定其他所有内容。
我还使用 RequestNavigate 将视图注入区域 - 我现在使用 MEF(当时我使用 Unity)。我发现这种方法更加灵活,尽管在调试方面有点“神奇”。
To answer my own question I've found that Prism v4 has provided a useful solution - a RegionExtension called RequestNavigate.
I have used RequestNavigate for opening a new window (check out StockTrader RI) however this seems extremely cumbersome, if following the proper MVVM methodology. Instead I've decided to use the ChildWindow class in the WPF Extended Toolkit, where you can purely bind to the 'WindowState' (open/closed) property, and specify everything else in XAML.
I've also used RequestNavigate for injecting views into Regions - I'm now using MEF (at the time I was using Unity). I find the approach a lot more flexible, if slightly 'magic' regarding debugging.