WPF 半透明窗体

来源:互联网 发布:面板数据加入虚拟变量 编辑:程序博客网 时间:2024/06/05 11:54
<Window x:Class="cn.lds.chatcore.pcw.Views.Page.Search"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:cn.lds.chatcore.pcw.Views.Page"
        mc:Ignorable="d"
        Title="Search" Height="300" Width="300"
        AllowsTransparency="True" WindowStyle="None" 
        Background="Transparent"
>
    <Grid Width="{Binding Width, ElementName=w}" Height="{Binding Height, ElementName=w}">
        <Border CornerRadius="0" Margin="2,2,2,2" BorderThickness="1" BorderBrush="White"Opacity="0.5">
            <!--<Border.Effect>
                <DropShadowEffect ShadowDepth="0" Color="#FF414141" BlurRadius="2"/>
            </Border.Effect>-->
            <Border Background="Black" Opacity="0.5" Margin="0" CornerRadius="0"/>
        </Border>
        <Grid>
            <ContentPresenter/>
        </Grid>
    </Grid>

</Window>

备注:Border用来实现透明效果,Grid用来显示控件,为了避免窗体内的控件变成透明的,所以Border,Grid必须处在同一级别上。

CornerRadius:设置圆角的,根据需要自行设定

DropShadowEffect : 设置阴影的,根据需要自行设定

以上部分缺一不可。




0 0
原创粉丝点击