zoukankan      html  css  js  c++  java
  • WPF-非矩形窗口的创建

    第一、窗口的AllowsTransparency设置为True

    第二、窗口的Background设置为Transparent

    第三、窗口的WindowStyle设置为None

    第四、窗口内的Grid用Clip或者Border设置为需要的形状

    代码示例(利用Clip实现圆角窗口)

     1 <Window x:Class="Test"
     2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     4         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     5         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     6         xmlns:local="clr-namespace:CaiPiaoUI"
     7         mc:Ignorable="d"
     8         Title="Test" Height="500" Width="500" WindowStyle="None" AllowsTransparency="True" 
     9         Background="Transparent" WindowStartupLocation="CenterScreen">
    10     <Grid Background="Blue">
    11         <Grid.Clip>
    12             <RectangleGeometry RadiusX="50" RadiusY="50" Rect="0,0,500,500"></RectangleGeometry>
    13         </Grid.Clip>
    14     </Grid>
    15 </Window>

    代码示例(利用Border实现圆角窗口)

     1 <Window x:Class="Test"
     2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     4         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     5         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     6         xmlns:local="clr-namespace:CaiPiaoUI"
     7         mc:Ignorable="d"
     8         Title="Test" Height="500" Width="500" WindowStyle="None" AllowsTransparency="True" 
     9         Background="Transparent" WindowStartupLocation="CenterScreen">
    10     <Grid>
    11         <Border BorderThickness="20" CornerRadius="50" Background="Blue"></Border>
    12     </Grid>
    13 </Window>

    这里特别注意一点,就是窗口背景色设置的位置:
    Clip实现方式中,窗口背景色设置在Grid上;

    Border实现方式中,窗口背景色设置在Border上。

  • 相关阅读:
    C#中子线程操作主线程中窗体上控件的方法
    关于VS2010在使用过程中的一些便捷之处
    WCF 开发日志 WCF契约设计
    OEA框架学习:运行时
    OEA框架学习:使用动软代码生成器
    OEA框架学习:多线程
    批处理定时自动更新SVN
    读书笔记:高效经理人的8个思维原则
    C# WinForm 技巧五:WinForm界面生成
    WCF开发日志 OEA里面的WCF设计
  • 原文地址:https://www.cnblogs.com/PolarisSky/p/4783828.html
Copyright © 2011-2022 走看看