Question Details

No question body available.

Tags

xaml winui-3 titlebar winui windows-app-sdk

Answers (1)

Accepted Answer Available
Accepted Answer
June 21, 2025 Score: 1 Rep: 15,525 Quality: High Completeness: 80%

I tried the following code from the GitHub repo, and it seems to be working:

public sealed partial class MainWindow : Window
{
    const int GWLEXSTYLE = -20;

const int WS
EXLAYOUTRTL = 0x00400000;

public MainWindow() { InitializeComponent(); ExtendsContentIntoTitleBar = true; SetTitleBar(AppTitleBar); TitleBarPageWindowGrid.FlowDirection = FlowDirection.RightToLeft; UpdateCaptionButtonDirection(FlowDirection.RightToLeft); }

[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")] internal static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, nint newProc);

[DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")] internal static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);

private static nint GetWindowHandleForCurrentWindow(object target) => WinRT.Interop.WindowNative.GetWindowHandle(target); private void UpdateCaptionButtonDirection(FlowDirection direction) { var hwnd = GetWindowHandleForCurrentWindow(this);

if (hwnd != 0) { var exStyle = GetWindowLongPtr(hwnd, GWL
EXSTYLE);

if (direction == FlowDirection.RightToLeft) { exStyle |= WSEXLAYOUTRTL; } else { exStyle &= ~WSEXLAYOUTRTL; }

SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle); } } }