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
.
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.
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…