Hi,@ quan zhao. Welcome to Microsoft Q&A. To enable the dark system menu with move, minimize, and maximize options in a WPF application, you could use the same Windows API functions. Here's how you can do it.
You can call the EnableDarkSystemMenu
method in the constructor of your MainWindow
or at any appropriate place in your application where you want to enable the dark system menu.
[DllImport("uxtheme.dll", EntryPoint = "#135", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern int SetPreferredAppMode(int preferredAppMode);
[DllImport("uxtheme.dll", EntryPoint = "#136", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern void FlushMenuThemes();
public MainWindow()
{
InitializeComponent();
EnableDarkSystemMenu();
}
private void EnableDarkSystemMenu()
{
SetPreferredAppMode(2); // Enable dark system menu
FlushMenuThemes();
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.