如何将变暗的半不透明效果应用于 WPF 窗口?

发布于 2024-08-18 18:11:07 字数 78 浏览 3 评论 0原文

当在某个过程中在 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 技术交流群。

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

发布评论

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

评论(2

天冷不及心凉 2024-08-25 18:11:07

最简单的方法是在要调暗的控件和进度条之间放置一个半透明矩形,然后在操作正在进行时使其可见。

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.

旧时浪漫 2024-08-25 18:11:07

在 silverlight 中,您可以使用自定义用户控件来执行此操作,并将其宽度和高度设置为“自动”。您将有一些控制,因为 LayoutRoot 的宽度和高度也设置为自动,并且在其中您将使进度条居中于中间(Horizo​​ntalAlignment = Center)。然后,您可以将 LayoutRoot 的不透明度设置为 0.5 或您喜欢的任何值。

然后,当您将控件嵌入到表单的 XAML 中时,您可以将控件的 Horizo​​ntalAlignment 和 VerticalAlignment 设置为拉伸。这会导致控件的布局根拉伸以填充您的表单,并且由于它的不透明度,您的表单变得半可见。由于您的进度条未设置为拉伸,因此它将保留在中间。

中是大致相同的

我想这在 WPF示例控件

<UserControl x:Name="MyControl" width="Auto" Heigh="Auto">
    <Grid x:Name="LayoutRoot" Background="#AFFFFFFF" Width="Auto" Height="Auto" Opacity="0.01" >
        <ProgressBar Height="10" VerticalAlignment="Center" HorizontalAlignment="Center" Width="195" IsIndeterminate="True" Background="Black" Foreground="#FFFF0009">
        </ProgressBar>
    </Grid>
</UserControl>

:示例用法:

<MyControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />

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:

<UserControl x:Name="MyControl" width="Auto" Heigh="Auto">
    <Grid x:Name="LayoutRoot" Background="#AFFFFFFF" Width="Auto" Height="Auto" Opacity="0.01" >
        <ProgressBar Height="10" VerticalAlignment="Center" HorizontalAlignment="Center" Width="195" IsIndeterminate="True" Background="Black" Foreground="#FFFF0009">
        </ProgressBar>
    </Grid>
</UserControl>

Example Usage:

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