如何将变暗的半不透明效果应用于 WPF 窗口?
当在某个过程中在 WPF 窗口上显示进度条时,我希望窗口的其余部分变得半可见,也许有一些颜色混合。
怎么可能达到这样的效果呢?
When showing a progress bar over WPF window during some process, I would like the rest part of the window gets semi-visible, maybe with some color blend.
How is it possible to achieve such effect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是在要调暗的控件和进度条之间放置一个半透明矩形,然后在操作正在进行时使其可见。
The easiest way is to place a semi-transparent rectangle between the controls you want to dim and the progress bar and then just make it visible while your operation is in progress.
在 silverlight 中,您可以使用自定义用户控件来执行此操作,并将其宽度和高度设置为“自动”。您将有一些控制,因为 LayoutRoot 的宽度和高度也设置为自动,并且在其中您将使进度条居中于中间(HorizontalAlignment = Center)。然后,您可以将 LayoutRoot 的不透明度设置为 0.5 或您喜欢的任何值。
然后,当您将控件嵌入到表单的 XAML 中时,您可以将控件的 HorizontalAlignment 和 VerticalAlignment 设置为拉伸。这会导致控件的布局根拉伸以填充您的表单,并且由于它的不透明度,您的表单变得半可见。由于您的进度条未设置为拉伸,因此它将保留在中间。
中是大致相同的
我想这在 WPF示例控件
:示例用法:
In silverlight you would do this with a custom user control with it's width and height set to "Auto". You would have a some control as the LayoutRoot with width and height also set to auto and within that you would have your progress bar centered in the middle (HorizontalAlignment=Center). You would then set the opacity of the LayoutRoot to be 0.5 or whatever you like
Then when you embed the control in the XAML for your form, you would set the control's HorizontalAlignment and VerticalAlignment to stretch. This causes the control's layout root to stretch to fill your form and because of it's opacity your form becomes semi-visible. Because your progress bar is not set to stretch, it will remain in the center.
I imagine it's much the same in WPF
Example control:
Example Usage: