WPF-create a non-rectangle window, And WPF-create a rectangle window

Source: Internet
Author: User

WPF-create a non-rectangle window, And WPF-create a rectangle window

1. Set AllowsTransparency of the window to True.

2. Set the Background of the window to Transparent.

Third, set WindowStyle to None in the window.

4. Use Clip or Border to set the Grid in the window to the desired shape.

 

Code example (using Clip to implement the rounded corner window)

 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>

Code example (using Border to implement the rounded corner window)

 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>

 

Note that the position of the background color of the window is as follows:
In Clip implementation mode, the background color of the window is set on the Grid;

In Border implementation mode, the background color of the window is set on Border.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.