简体   繁体   English

在WPF中创建透明背景

[英]Creating transparent background in WPF

I have a button with a backgroun image of color white. 我有一个带有白色背景图像的按钮。 My button is sitting on the toolbar which has a bacground color of Blue. 我的按钮位于工具栏上,其颜色为蓝色。 When the button is sitting on the toolbar, the button looks white, however I want it to look like blue as the the background color of toolbar is Blue. 当按钮位于工具栏上时,按钮看起来是白色的,但我希望它看起来像蓝色,因为工具栏的背景颜色是蓝色。

How should I achieve this in WPF.. Please let me know. 我应该如何在WPF中实现这一点..请让我知道。

Are you sure you want to use an image? 您确定要使用图像吗? If the image is just a solid color, you're probably better off just setting the button's background to white and adjusting its opacity. 如果图像只是纯色,那么将按钮的背景设置为白色并调整其不透明度可能会更好。 Like: 喜欢:

<Button Background="White" Opacity="0.5" />

Where Opacity can be any value between 0 and 1. 其中Opacity可以是0到1之间的任何值。

EDIT : I'm not sure what you mean by "shades." 编辑 :我不确定你的意思是“阴影”。 Are you aware that you can set the background of a Button to a gradient? 您是否知道可以将Button的背景设置为渐变? You'll want to change the colors I'm sure, but it will look something like this: 你想要改变我确定的颜色,但它看起来像这样:

<Button>
    <Button.Background>
        <LinearGradientBrush>
            <GradientStop Color="Yellow" Offset="0.0" />
            <GradientStop Color="Orange" Offset="0.5" />
            <GradientStop Color="Red" Offset="1.0" />
         </LinearGradientBrush>
    <Button.Background>
</Button>

您可以使用System.Windows.Media.Color Transparent ,如下所示:

<Button Background="Transparent" />

You have to make sure your image has transparency, WPF won't try to figure out what parts in your image should be see-through and what parts should be opaque. 你必须确保你的图像具有透明度,WPF不会试图弄清楚图像中的哪些部分应该是透明的,哪些部分应该是不透明的。 Check that your image editor can export images with transparency, most likely to PNG. 检查您的图像编辑器是否可以导出具有透明度的图像,最有可能导致PNG。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM