如何添加一个半透明的灯罩上的WPF元素? [英] How to add a semi-transparent shade over elements in WPF?

查看:144
本文介绍了如何添加一个半透明的灯罩上的WPF元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想补充一个半透明的颜色在一个WPF窗口中的内容(以指示窗口的状态)。目前我使用一个用户控件,填补了窗口,我根据需要更改背景颜色和可见性。

I would like to add a semi-transparent colour over the contents of a WPF window (to indicate the state of the window). Currently I am using a UserControl that fills the Window, and I change the Background colour and Visibility as required.

使用这种方法的问题是,当用户控件是可见的,我不能点击的用户控件后面的窗口中的任何控件(按钮,复选框)。我想我需要让用户控件透明的点击不知。这是可能的,或者有没有更好的方式来增加颜色在窗口?

The problem with this method is when the UserControl is visible, I cannot click any controls (Buttons, CheckBoxes) in the Window behind the UserControl. I guess I need to make the UserControl transparent to clicks somehow. Is this possible, or is there a better way to add the colour over the Window?

推荐答案

您可以设置 IsHitTestVisible 上您的遮盖件。

You could set IsHitTestVisible to False on your masking element.

<Grid>
   <Button>Background Button</Button>
   <Rectangle Fill="Blue" Opacity="0.25" IsHitTestVisible="False"/>
</Grid>

尝试XAML在类似 Kaxaml 。您仍然可以按一下按钮,但在蓝色矩形将psented过顶$ P $。它是半透明的,由于低不透明度设置

Try that XAML out in something like Kaxaml. You will still be able to click the button, yet the blue rectangle will be presented over the top. It is semi-transparent due to the low opacity setting.

这篇关于如何添加一个半透明的灯罩上的WPF元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆