如何使正在运行的 WPF 应用程序窗口透明?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25443043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make running WPF application window transparent?
提问by Piotr Owsiak
I have a piece of AutoHotKey script that allows me to set transparency on an active window but it does not work with WPF application like Powershell ISE.
我有一段 AutoHotKey 脚本,它允许我在活动窗口上设置透明度,但它不适用于像 Powershell ISE 这样的 WPF 应用程序。
Is there a way to do that?
有没有办法做到这一点?
EDIT: As is stated in the question I need to do that on a running WPF app like Powershell ISE.
编辑:正如问题中所述,我需要在运行的 WPF 应用程序(如 Powershell ISE)上执行此操作。
回答by Maximus
Set this in Window element
在 Window 元素中设置
AllowsTransparency="True" WindowStyle="None" Background="Transparent"
回答by Stígandr
Hi WPF is based on Direct3D, and is a bit different from win32 and forms which is based on GDI/GDI+.
您好,WPF 基于 Direct3D,与 win32 和基于 GDI/GDI+ 的窗体略有不同。
In WPF you do this in your xaml(see example by maximus) or create your own window style.
在 WPF 中,您可以在 xaml 中执行此操作(请参阅 maximus 的示例)或创建您自己的窗口样式。
There is a post here on how you should do this in WPF.
Another slightly related question.
A style :
一种风格:
<Style TargetType="Window" x:Key="TransparentWindowStyle">
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="AllowsTransparency=" Value="True"/>
<Setter Property="Background" Value="Transparent"/>
</Style>
Skip the x:Key and it will be applied to all windows or you have to place in app.xaml or a place where it is shared, and apply it to the window. A bit overkill for just 3 properties, but handy if you are going to do other changes, that should be applied to multiple windows.
跳过 x:Key 它将应用于所有窗口,或者您必须放置在 app.xaml 或共享它的地方,并将其应用于窗口。仅对 3 个属性来说有点矫枉过正,但如果您要进行其他更改(应应用于多个窗口),则很方便。
Hope it helps,
希望能帮助到你,
Stian
斯蒂安

