[WPF] C# Modify the windows border color.

Roy 21 Reputation points

So I am currently on Windows 11 using the https://github.com/MahApps/MahApps.Metro Framework which by default makes the window squared like windows 10, so I saw a post by Microsoft here https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/apply-rounded-corners which applies rounded corners to an application. But my question is how can I go about modifying the gray border that is drawn by the system on my window, to perhaps a different color for example?

Below is my MainWindow.cs

 /// <summary>  
    /// Interaction logic for MainWindow.xaml  
    /// </summary>  
    public partial class MainWindow  
        #region Window Corner Round  
        public enum DWMWINDOWATTRIBUTE  
        // The DWM_WINDOW_CORNER_PREFERENCE enum for DwmSetWindowAttribute's third parameter, which tells the function  
        // what value of the enum to set.  
        public enum DWM_WINDOW_CORNER_PREFERENCE  
            DWMWCP_DEFAULT = 0,  
            DWMWCP_DONOTROUND = 1,  
            DWMWCP_ROUND = 2,  
            DWMWCP_ROUNDSMALL = 3  
        // Import dwmapi.dll and define DwmSetWindowAttribute in C# corresponding to the native function.  
        [DllImport("dwmapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]  
        private static extern long DwmSetWindowAttribute(IntPtr hwnd,  
            DWMWINDOWATTRIBUTE attribute,  
            ref DWM_WINDOW_CORNER_PREFERENCE pvAttribute,  
            uint cbAttribute);  
        public MainWindow()  
            DataContext = this;  
            #region Window Rounding Initialization  
            IntPtr hWnd = new WindowInteropHelper(GetWindow(this)).EnsureHandle();  
            var preference = DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUND;  
            DwmSetWindowAttribute(hWnd, attribute, ref preference, sizeof(uint));  



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,365 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
8,185 questions
{count} votes