First, the window's allowstransparency is set to True
Second, the window's background is set to Transparent
Third, the window's windowstyle is set to None
The grid in the window is set to the desired shape using clip or border
code example (using clip to implement a fillet window)
1 <Windowx: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= "$"Width= "$"WindowStyle= "None"allowstransparency= "True" 9 Background= "Transparent"windowstartuplocation= "Centerscreen">Ten <GridBackground= "Blue"> One <Grid.clip> A <RectangleGeometryRadiusX= " the"RadiusY= " the"Rect= "0,0,500,500"></RectangleGeometry> - </Grid.clip> - </Grid> the </Window>
code example (using border to implement a fillet window)
1 <Windowx: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= "$"Width= "$"WindowStyle= "None"allowstransparency= "True" 9 Background= "Transparent"windowstartuplocation= "Centerscreen">Ten <Grid> One <Borderborderthickness= " the"Cornerradius= " the"Background= "Blue"></Border> A </Grid> - </Window>
One particular note here is the location of the window background color setting:
In the clip implementation mode, the window background color is set on the grid;
In the border implementation mode, the window background color is set on the border.
wpf-creation of non-rectangular windows