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

本文详细介绍了如何使用WindowsStyle、Background、AllowsTransparency和Opacity等属性进行窗口透明度与背景设置,并提供了工程代码下载。主要内容包括:1. 控制窗口整体透明度;2. 设置空白部分为全透明,控件部分显示颜色;3. 设置空白部分半透明,控件部分保持不透明。通过这些设置,可以实现不同风格的窗口外观。

一般使用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.youkuaiyun.com/detail/yysyangyangyangshan/5096470

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值