WPF窗口,透明背景包含不透明控件

kma*_*ks2 49 .net c# wpf user-interface transparency

我有一个窗口,外观如下:

在此输入图像描述

然而,我想要的是,主体中的Button控件(中间带有文字的灰色控件)的不透明度为1,完全不透明.当我继承这个项目时,不透明度在开始标记内的顶层设置为0.75 .现在据我了解,这将自动强制执行所有孩子,并说孩子不能覆盖.WindowGridWindow

那我怎么能完成透明背景但不透明的按钮呢?到目前为止我找到的唯一方法(作为WPF中的相对新手)是有两个单独的Windows,一个是透明背景,另一个没有背景但包含不透明控件.这非常hacky,如果可以,我想避免它.

我可以根据要求提供代码,但它实际上就像Window使用windowstyle = none和opacity .75 一样简单Grid,其中包含一些非常基本的Buttonetc控件.

有没有人建立过这样的Window,或者有其他人有洞察力生成一个?谢谢.

svi*_*nja 98

而不是设置窗口的不透明度,设置其背景的不透明度:

<Window x:Class="WpfApplication3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        AllowsTransparency="True" WindowStyle="None">
    <Window.Background>
        <SolidColorBrush Opacity="0.5" Color="White"/>
    </Window.Background>
    <Grid>
        <Button Width="200" Height="50">button</Button>
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)