WPF设计の不规则窗体

  我们在工作中,经常会需要画一些不规则的窗体,现在总结如下。

一、利用VisualBrush实现。这依赖于VisualBrush的特性,任何控件可以作为画刷,而画刷又可以作为背景。

        此种方法可以用于实现一些文字窗体等。(注意设置窗体的透明属性)

  例如:

<Window x:Class="IconFontTest.Window1"
        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:IconFontTest"
        mc:Ignorable="d" AllowsTransparency="True" WindowStyle="None"
        WindowStartupLocation="CenterScreen"
        Title="Window1" Height="400" Width="600">

    <Window.Background>
        <VisualBrush>
            <VisualBrush.Visual>
                <TextBlock>好好学习</TextBlock>
            </VisualBrush.Visual>
        </VisualBrush>
    </Window.Background>

</Window>

实现的效果:

二、使用透明背景的png图片实现。(当然注意设置透明属性)

<Window x:Class="WPFSharpWindow.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="412" Width="528" 
        AllowsTransparency="True" WindowStyle="None" OpacityMask="White" Background="Transparent">
    <Grid MouseLeftButtonDown="Grid_MouseLeftButtonDown">
        <Image Stretch="Fill" Source="/WPFSharpWindow;component/cow.png" />
    </Grid>
</Window>

三、利用windows的Clip。

         给window的Clip属性赋Path值。

在XAML中定义一个Path,如下:

<Path Visibility="Hidden" x:Name="clipPath"
          Data="M 55,100 A 50,50 0 1 1 100,60 A 110,95 0 0 1 200, 60 A 50,50 0 1 1 250,100 A 110,95 0 1 1 55,100 Z"/>
赋值:

window1.Clip = clipPath.Data;

当然也可以在前台赋值。

四、添加Border实现

以上的本质都是将窗体设置成透明然后添加不规则窗体。

转载于:https://www.cnblogs.com/xietianjiao/p/7641616.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值