How to Create Rounded Corners WPF Window?

Sarah 186 Reputation points
2022-02-23T18:02:05.56+00:00

How can i create rounded corners WPF Window using WindowStyle as in the picture below? 177248-rounded-corners.png

@Peter Fleischer (former MVP) Can you help? it's your window!

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,783 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Hui Liu-MSFT 48,571 Reputation points Microsoft Vendor
    2022-02-25T06:00:38.697+00:00

    You could set AllowsTransparency="True" Background="Transparent" WindowStyle="None" and customize events such as maximize, minimize, and close for Window. You can also try to use the WindowChrome class.
    MainWindow.xaml.cs:

    <Window x:Class="RoundCornerWindow.MainWindow"  
            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:RoundCornerWindow" x:Name="window"  
            mc:Ignorable="d" AllowsTransparency="True" Background="Transparent" WindowStyle="None"  
            Title="MainWindow" Height="450" Width="800">  
        <Border CornerRadius="25" BorderBrush="Black" BorderThickness="2" Padding="6" Background="GhostWhite">  
            <Grid>  
                <Grid VerticalAlignment="Top" Height="30" HorizontalAlignment="Right" Width="230" Margin="0,5,5,0" >  
                    <Button Content="*"  Width="25" Margin="200,0,6,0" Click="Close_Click"/>  
                    <Button Content="[]"  Width="25"  Margin="170,0,32,0" Click="Maximize_Click"/>  
                    <Button Content="-" Width="25"  Margin="125,0,44,0" Click="Minimize_Click"/>  
                </Grid>  
            </Grid>  
        </Border>  
    </Window>  
    

    MainWindow.xaml.cs:

     public partial class MainWindow : Window  
      {  
        public MainWindow()  
        {  
          InitializeComponent();  
        }  
        private void Close_Click(object sender, RoutedEventArgs e)  
        {  
         window.Close();  
        }  
        private void Maximize_Click(object sender, RoutedEventArgs e)  
        {  
          if (window.WindowState == WindowState.Normal)  
          {  
            window.WindowState = WindowState.Maximized;  
          }  
          else  
          {  
            window.WindowState = WindowState.Normal;  
          }  
        }  
        private void Minimize_Click(object sender, RoutedEventArgs e)  
        {  
          window.WindowState = WindowState.Minimized;  
        }  
    }  
    

    The result:
    177733-image.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    3 people found this answer helpful.

  2. Castorix31 85,806 Reputation points
    2022-02-23T18:07:29.783+00:00

    With CornerRadius
    (I had posted a basic sample in this thread for another problem (shadow))


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.