更改背景透明度不改变内容的不透明度 [英] Change Background opacity without changing content opacity

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

问题描述

我想知道我怎样才能改变WPF窗口背景的透明度不影响内部子控件。当我的窗口属性不透明度更改为0.5我得到一个半透明的窗口,但窗口内的图像也继承了0.5的不透明度值,凭什么我只是做的不透明度为窗口只?

I wanted to know how can I change the opacity of the background of the WPF Window without effecting the inner child controls. When I change the Window property 'Opacity' to 0.5 I do get a semi-transparent window, but the image inside the window also inherited the 0.5 opacity value, so how can I just make the opacity for the window only?

推荐答案

该窗口是一切的父容器因此设置窗口中的透明度将影响它包含的一切。我想你想要做的是改变 Window.Background 透明度

The window is the parent container of everything so setting the opacity on the window will effect everything that it contains. I think what you want to do is change the Opacity of the Window.Background.

启用窗口做透明涉及两件事情以复加。首先,你需要设置 Window.AllowsTransparency = TRUE 键,还可以设置 Window.WindowStyle =无 WindowStyle.None 创建无窗口镶边的最小化,最大化和关闭按钮的窗口,所以你必须处理自己的应用程序以及调整大小和移动窗口。之后,一切都做了,那么您可以设置 Window.Background 来有一个透明度在其上设置一刷。

Enabling a window to do transparency involves a couple things to be added. First, you will need to set Window.AllowsTransparency = True and also set the Window.WindowStyle = None. WindowStyle.None creates a window without the minimize, maximize, and close buttons in the window chrome so you'll have to handle that in the application yourself along with resizing and moving the window. After that's all done, then you can set the Window.Background to have a brush with an Opacity set on it.

下面code样品会告诉你如何让窗口总是透明,并设置窗口背景的透明度有不同的不透明度。

The following code sample will show you how to have the window always transparent and set the opacity of the window background to have a different opacity.

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="WpfApplication1.MainWindow"
        x:Name="Window"
        WindowStyle="None"
        AllowsTransparency="True">
    <Window.Background>
        <SolidColorBrush Color="White" Opacity="0.5"/>
    </Window.Background>
    <Grid>
        <!--Window Content-->
    </Grid>
</Window>

您可以随时设置窗口背景为透明,如果你只是想在窗口中的元素是可见的。

You can always set the window background to transparent if you only want the elements in the window to be visible.

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

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