Non-Rectangular window : Window Style « Windows Presentation Foundation « C# / CSharp Tutorial






<Window x:Class="Windows.TransparentWithShapes"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="NonRectangularWindowSample" Width="210" Height="170"
  WindowStyle="None" AllowsTransparency="True" Background="Transparent">
  <Grid>
    <Path Stroke="DarkGray" StrokeThickness="1" SnapsToDevicePixels="True">

      <Path.Fill>
        <LinearGradientBrush StartPoint="0.2,0" EndPoint="0.8,1" >
          <LinearGradientBrush.GradientStops>
            <GradientStop Color="White"  Offset="0"></GradientStop>
            <GradientStop Color="White"  Offset="0.45"></GradientStop>
            <GradientStop Color="LightBlue" Offset="0.9"></GradientStop>
            <GradientStop Color="Gray" Offset="1"></GradientStop>
          </LinearGradientBrush.GradientStops>
        </LinearGradientBrush>
      </Path.Fill>

      <Path.Data>
        <PathGeometry>
          <PathGeometry.Figures>
            <PathFigure StartPoint="20,0" IsClosed="True">
              <LineSegment Point="140,0"></LineSegment>
              <ArcSegment Point="160,20" Size="20,20" SweepDirection="Clockwise"></ArcSegment>
              <LineSegment Point="160,60"></LineSegment>
              <ArcSegment Point="140,80" Size="20,20" SweepDirection="Clockwise"></ArcSegment>
              <LineSegment Point="70,80"></LineSegment>
              <LineSegment Point="20,80"></LineSegment>
              <ArcSegment Point="20,0" Size="20,20" SweepDirection="Clockwise"></ArcSegment>
            </PathFigure>
          </PathGeometry.Figures>
        </PathGeometry>
      </Path.Data>
      <Path.RenderTransform>
        <ScaleTransform ScaleX="1.3" ScaleY="1.3"></ScaleTransform>
      </Path.RenderTransform>

    </Path>

    <StackPanel Margin="5">
      <Button HorizontalAlignment="Right" Click="cmdClose_Click" Margin="0,5,10,0">x</Button>
    </StackPanel>
  </Grid>
</Window>
//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Input;

namespace Windows {

    public partial class TransparentWithShapes : Window
    {
        public TransparentWithShapes()
        {
            InitializeComponent();
        }

        private void window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void cmdClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
WPF Non Rectangular Window








24.72.Window Style
24.72.1.Window BackgroundWindow Background
24.72.2.Create a non-rectangular windowCreate a non-rectangular window
24.72.3.Transparent WindowTransparent Window
24.72.4.Non-Rectangular windowNon-Rectangular window
24.72.5.Windows Transparent BackgroundWindows Transparent Background
24.72.6.Set WindowStyle = WindowStyle.ToolWindow
24.72.7.Set brush to Window background