WPF 和 Prism 视图叠加

发布于 2024-08-25 09:18:09 字数 398 浏览 5 评论 0原文

我需要一些帮助来使用 prism 框架覆盖视图。它比这更复杂一点,所以让我解释一下。我也可能想得太多了:D

我有 shell(wpf 窗口)并且我有 2 个视图(A & ; B - 模块中的两个用户控件。 当 shell 加载时,它会加载视图 A。在视图 A 上,我有一个“弹出”视图 B 的按钮 对于一些用户输入。所以很自然地我会想到某种模式窗口/控件,甚至可能是弹出窗口。然而,我面对弹出窗口的问题是,当我移动外壳时,弹出窗口保持固定,并且它不会阻止视图 A 中的事件。我尝试禁用视图 A 以停止触发事件,并且我还尝试使用让视图 B 随 shell 一起移动。只有画布有效,但我现在需要一种方法来阻止它。无论如何,我可以用棱镜将一个视图叠加在另一个视图之上吗?或者其他人如何使用 prism & 创建模式弹出窗口wpf?任何建议或指示将不胜感激。

I need some help with overlaying views using the prism framework.Its a little more complexed than that so let me explain.I could be over-thinking this as well :D

i have shell (wpf window) and i have 2 views(A & B - both usercontrols) in a module.
when the shell loads it loads view A. On view A i have a button to "popup" view B
for some user input. so naturally i would think to some sort of modal window/control, maybe even a popup. however the problem i face with the popup is that when i move the shell the popup remains fixed and it doesnt block events in view A. I've tried disabling view A to stop events being fired and i've also tried to use a to get the view B move with the shell. Only the canvas works but i now need a way to block it tho'. Is there anyway i can overlay a view on top of another view with prism? or how does everyone else create modal popups with prism & wpf? any advise or pointers would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧时光的容颜 2024-09-01 09:18:09

如果您想使用没有额外窗口的嵌入式对话框,您可以使用 Prism 的 RegionManager 来实现概述的行为。诀窍是将 PopUp 区域与可视树中的主区域平行:

<Grid>
   <ContentControl cal:RegionManager.RegionName="MainRegion" IsEnabled={Binding IsNoPopUpActive} />
   <ContentControl cal:RegionManager.RegionName="PopUpRegion"/>
</Grid>

现在使用 RegionManager 将视图“A”放入“MainRegion”中。创建一个类似于IPopUpDialogController 的控制器类。它应该负责根据需要将您的视图“B”(或应用程序中的任何其他 PopUpView)放入“PopUpRegion”中。此外,它还应该控制一个标志,指示要启用或禁用的底层“MainRegion”。这样,在弹出窗口关闭之前,用户将无法使用视图“A”中的控件。

这甚至可以在将帧推送到调度程序之前使用 ComponentDispatcher.PushModal() 以模态方式完成。但是,我建议避免模式对话框。


更新:根据评论中的要求,IsNoPopUpActive 可以在支持视图模型中实现。在那里,您可以将其链接到弹出区域的 RegionManager 视图集合:

public bool IsNoPopUpActive 
{ 
    get { return _regionManager.Regions["PopUpRegion"].Views.Count() == 0; }
}

请记住在修改视图集合(添加/删除弹出窗口)后立即触发 PropertyChanged 事件。

仅供参考:现在我避免禁用后台控件,而是插入一个透明面板。这可以避免点击后台控件。但是,这不处理键盘输入(按 Tab 键切换到控件)。要修复键盘输入,您需要确保键盘焦点被捕获在弹出窗口中(MSDN 上的 WPF Focus 概念)。

将以下焦点属性添加到弹出区域应该可以解决问题:

KeyboardNavigation.DirectionalNavigation="None"
KeyboardNavigation.ControlTabNavigation="None"
KeyboardNavigation.TabNavigation="Cycle"
KeyboardNavigation.TabIndex="-1"

If you want to use embedded dialogs without an extra window, you can use Prism's RegionManager to achieve the outlined behavior. The trick is to put the PopUp region parallel to your main region in the visual tree:

<Grid>
   <ContentControl cal:RegionManager.RegionName="MainRegion" IsEnabled={Binding IsNoPopUpActive} />
   <ContentControl cal:RegionManager.RegionName="PopUpRegion"/>
</Grid>

Now use the RegionManager to put view "A" into the "MainRegion". Create a controller class similar to IPopUpDialogController. It should be responsible for putting your view "B" (or any other PopUpView in your application) into the "PopUpRegion" on demand. Addtionally, it should control a flag that signal the underlying "MainRegion" to be enabled or disabled. This way a user won't be able to play with the controls in your view "A" until the pop up is closed.

This can even be done in a modal fashion by using ComponentDispatcher.PushModal() before pushing a frame onto the Dispatcher. However, I would recommend avoid modal dialogs.


Update: As requested in a comment, the IsNoPopUpActive could be implemented in the backing view model. There you could link it to RegionManager's View collection for the popup region:

public bool IsNoPopUpActive 
{ 
    get { return _regionManager.Regions["PopUpRegion"].Views.Count() == 0; }
}

Remember to trigger a PropertyChanged event as soon as you modify the views collection (add/remove a popup).

Just for your information: nowadays I avoid disabling the controls in the background and instead insert a transparent panel. This avoids clicking on background controls. However, this does not handle keyboard input (tab-ing to controls). To fix the keyboard input you need to make sure that the keyboard focus is trapped in the popup (MSDN on WPF Focus concepts).

Adding the following focus attributes to the popup region should do the trick:

KeyboardNavigation.DirectionalNavigation="None"
KeyboardNavigation.ControlTabNavigation="None"
KeyboardNavigation.TabNavigation="Cycle"
KeyboardNavigation.TabIndex="-1"
零時差 2024-09-01 09:18:09

如果您使用 WPF + MVVM 和 Prism,您可以看看这个消息视图覆盖控制器。这种方法的好处是,您可以使用模拟覆盖控制器在视图模型上编写单元测试,并让模拟控制器返回用户在覆盖中选择的结果。

您可以在这里找到它:http://presentationlayer。 wordpress.com/2011/05/24/wpf-overlay-message-view-controller/

希望这有帮助

If you are using WPF + MVVM with Prism you can take a look at this Message View overlay controller. The nice part about this approach is you can write unit tests on you view model using a mock overlay controller and have the mock controller return the result that the user would choose in the overlay.

You can find it here: http://presentationlayer.wordpress.com/2011/05/24/wpf-overlay-message-view-controller/

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文