Skip to content

[WPF] C# gray border persists around window #5627

@vsfeedback

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


[severity:It bothers me. A fix would be nice]
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://docs.microsoft.com/en-us/windows/apps/desktop/modernize/apply-rounded-corners which applies rounded corners. 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? I would like the border to match my app theme.

Below is my MainWindow.cs

///


/// Interaction logic for MainWindow.xaml
///

public partial class MainWindow

{

#region Window Corner Round

public enum DWMWINDOWATTRIBUTE
{
DWMWA_WINDOW_CORNER_PREFERENCE = 33
}

// 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);
#endregion
public MainWindow()
{
InitializeComponent();

DataContext = this;

#region Window Rounding Initialization

IntPtr hWnd = new WindowInteropHelper(GetWindow(this)). EnsureHandle();
var attribute = DWMWINDOWATTRIBUTE. DWMWA_WINDOW_CORNER_PREFERENCE;
var preference = DWM_WINDOW_CORNER_PREFERENCE. DWMWCP_ROUND;
DwmSetWindowAttribute(hWnd, attribute, ref preference, sizeof(uint));

#endregion
}
}

[border-color.png] (https://aka.ms/dc/file?name=B41a02384596e4bd59e3598a2b0076874637685580918623845_border-color.png&tid=41a02384596e4bd59e3598a2b0076874637685580918623845)


Original Comments

Feedback Bot on 9/30/2021, 00:37 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions