模糊不透明度 [英] blurred opacity

查看:53
本文介绍了模糊不透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个透明的模糊背景.假设我有一个带有白色模糊透明背景的边框.边界后面的一切都是模糊的.

我试图避免依赖;我目前正在使用 .NET 3.0,并希望它也能与 XP 一起运行.

样机图片:

解决方案

VisualBrush 可用于接近您想要的内容,但有一些限制.

只要您只需要窗口内的玻璃效果(而不是其他窗口上的效果)并且玻璃效果边框的位置受到严格控制,那么您可以像这样:-

 <网格><Border x:Name="src";背景=银"><标签水平对齐=中心"VerticalAlignment=中心"FontSize=50">Hello World</Label></边框><边框背景=白色"保证金=40"><边框不透明度=0.5"><边框效果><BlurEffect Radius=10"/></Border.Effect><边框.背景><VisualBrush Visual="{Binding ElementName=src}";拉伸=无"/></Border.Background></边框></边框></网格>

我不认为可视化树中的子元素能够获取其父元素的 VisualBrush,因此这对您来说可能是一个限制.(即玻璃面板不能被背景面板包含)

我多次使用 VisualBrushes,通常与 TranslateTransforms 一起移动它们以在正确的位置获得正确的图像.

更新:

更改了 XAML 以使用 Effect 而不是 BitmapEffect,后者速度较慢,现在已折旧,正如 Steven Robbins 在下面的评论中所述.>

I need to create a transparent blurred background. Lets suppose I have a border with a white blurry transparent background. Everything that is behind the border is blurred.

I'm trying to avoid dependencies; I'm currently using .NET 3.0, and want it to run with XP too.

Mockup image:

解决方案

A VisualBrush can be used to get close to what you want, but has some limitations.

As long as you only need the glass effect within the window (and not be an effect over other windows) and that the placement of the glass effect border is controlled tightly then you could you something like this:-

  <Grid>
    <Border x:Name="src" Background="Silver">
      <Label HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="50">Hello World</Label>
    </Border>
    <Border Background="White" Margin="40" >
      <Border Opacity="0.5" >
          <Border.Effect>
            <BlurEffect Radius="10"/>
          </Border.Effect>
        <Border.Background>
          <VisualBrush  Visual="{Binding ElementName=src}" Stretch="None" />
        </Border.Background>
      </Border>
    </Border>
  </Grid>

I don't think that a child element within the visual tree is able to get the VisualBrush of it's parent so this might be a limitation for you. (i.e. the glass panel cannot be contained by the background panel)

I've used VisualBrushes many times usually with TranslateTransforms to move them around a bit to get the right image in the right place.

Update:

Altered XAML to use Effect and not BitmapEffect that is slower and now depreciated as mentioned in the comments below by Steven Robbins.

这篇关于模糊不透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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