寻找一个透明,点击通过叠加一个很好的解决方案,WPF

问题描述:

我想尝试不同的东西,并在尝试以显示我目前的WPF图形用户界面,允许用户仍然与GUI交互上重叠,但提供烦恼一层,让他们知道的东西的了。

I want to try something different, and am attempting to display an overlay on top of my current WPF GUI that allows the user to still interact with the GUI, but provides a layer of annoyance to let them know that something's up.

我的问题实际上是两个独立的问题:

My question is really two separate questions:

1。你会怎么做覆盖?

我的第一次尝试是使用一个矩形,填充设置为适当的颜色,然后更改不透明度。但它不是透明的点击率。所以,我想我想做的事情,根据搜索结果,是创建一个单独的窗口,它的背景设置为透明,然后设置AllowsTransparency为True。虽然这个作品,如果我想要做的事,比如背景=DarkRed透明度=0.2,点击率不再工作

My first attempt was to use a Rectangle, set the Fill to the appropriate color, and then change the Opacity. But it's not transparent to click-throughs. So I think what I want to do, according to search results, is to create a separate window, set its Background to Transparent, and then set AllowsTransparency to True. While this works, if I want to do something like Background="DarkRed" Opacity="0.2", click-throughs no longer work.

这使我的第二部分:

2。什么是如果我使用调整本重叠区的正确方法MVVM?

我的主窗口创建视图模型,创建模型。模型是知道该覆盖是否应显示的唯一事情。但主窗口明明是知道它的大小的唯一的事情,而Model从不知道它高于一切。是实现这一数据绑定的叠加窗口的大小,在视图模型属性,然后有视图模型设置这些值的任何时间的唯一方法主窗口的大小变化?

My main window creates the ViewModel, which creates the Model. The Model is the only thing that knows about whether or not the overlay should be displayed. But the main window obviously is the only thing that knows its size, and the Model never knows about anything above it. Is the only way to achieve this to databind the overlay Window's size to properties in the ViewModel, and then have the ViewModel set these values any time the main Window's size changes?

?任何人有我如何能做到所有这些事情的线索

Anyone have clues on how I can achieve all of these things?

要解决第1部分:设置 IsHitTestVisible =FALSE您的叠加,无论是矩形,边境或其他一些元素。这将让你做出你想要什么颜色和透明度水平,而不会影响与底层控制交互

To address part 1: set IsHitTestVisible="False" on your overlay, be it a Rectangle, Border or some other element. This will allow you to make it whatever color and transparency level you want without affecting interaction with the underlying controls.

2部分:你不应该使用一个单独的窗口。如果你把覆盖在主窗口中,你可以依靠在视图中自动处理覆盖的尺寸布局。

Part 2: you shouldn't use a separate Window. If you keep the overlay in the main Window you can rely on the layout in your view to automatically handle sizing of the overlay.