您的位置:首页 > 其它

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

2013-02-28 17:18 811 查看
一般使用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

本文出自 “西北白杨树” 博客,请务必保留此出处http://yangyoushan.blog.51cto.com/7229571/1276422
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: