WPR-007:WPF中窗体的透明设置

来源:互联网 发布:童装代理一手货源淘宝 编辑:程序博客网 时间:2024/05/20 02:27

一般使用WindowStyle=,Background=,AllowsTransparency,Opacity来进行设置。
1、设置Opacity控制整个窗口的透明,包括上面的控件

Window x:Class="TestTransparentWindow.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="MainWindow" Height="441" Width="870"        WindowStyle="None"  AllowsTransparency="True" Opacity="0.5">    <Grid Width="500" Height="300" Background="Black">            </Grid></Window>

2、窗体空白部分全部透明,控件部分显示颜色
这种可是使用自定义的控件形状,来使窗体呈现自定义的形状

<Window x:Class="TestTransparentWindow.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="MainWindow" Height="441" Width="870"        WindowStyle="None"  AllowsTransparency="True" Background="#00FFFFFF">    <Grid Width="500" Height="300" Background="Black">           </Grid></Window>

3、空白部分半透明,控件部分不透明
依然使用Background设置颜色

<Window x:Class="TestTransparentWindow.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="MainWindow" Height="441" Width="870"        WindowStyle="None"  AllowsTransparency="True" Background="#AA000000">    <Grid Width="500" Height="300" Background="Black">          </Grid></Window>


工程代码下载:http://download.csdn.net/detail/yysyangyangyangshan/5096470

 

原创粉丝点击