Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not make RTL language application in WinUI 3 #8746

Open
ghost1372 opened this issue Jul 1, 2023 · 5 comments
Open

Can not make RTL language application in WinUI 3 #8746

ghost1372 opened this issue Jul 1, 2023 · 5 comments
Assignees
Labels
area-TitleBar Issues related to custom window title bars. bug Something isn't working team-Reach Issue for the Reach team

Comments

@ghost1372
Copy link
Contributor

ghost1372 commented Jul 1, 2023

Describe the bug

i want to make my winui 3 app RTL, this means All layouts, including the TitleBar and Custom TitleBar, should be right to left!
It is very strange that this was done easily in the previous versions.
But it is not possible in the latest version (1.3.2)

Steps to reproduce the bug

I did the following methods none of them change the language/layout of the app

Method Value TitleBar Content
MainWindow Top Level UIElement.FlowDirection RightToLeft No Change [LTR] Yes RTL
Package.appxmanifest DefaultLanguage = fa-IR or fa No Change [LTR] No Change [LTR]
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride fa-IR or fa No Change [LTR] No Change [LTR]
Thread.CurrentThread fa-IR or fa No Change [LTR] No Change [LTR]
m_resourceContext.QualifierValues["Language"] fa-IR or fa No Change [LTR] No Change [LTR]
Custom TitleBar (AppWindow) - Grid.FlowDirection RightToLeft No Change [LTR] No Change [LTR]

Expected behavior

At least one of the above methods should change the language of the program, but nothing happens.
I also changed the Windows Language settings, but nothing happens

Screenshots

No response

NuGet package version

Windows App SDK 1.3.2: 1.3.230602002

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 22H2 (22621, 2022 Update)

IDE

Visual Studio 2022

Additional context

No response

Tasks

No tasks being tracked yet.
@DarranRowe
Copy link

DarranRowe commented Jul 2, 2023

Just to be sure, have you tried adding the WS_EX_LAYOUTRTL EX style to the window, or have you called SetProcessDefaultLayout with LAYOUT_RTL?
Desktop applications are interesting in that they prefer LTR layouts even if the system language is set to one of the RTL languages. Raymond Chen did a blog post about this last year.

Screenshot 2023-07-02 113711

Screenshot 2023-07-02 115204

@ghost1372
Copy link
Contributor Author

tnx, using SetProcessDefaultLayout and WS_EX_LAYOUTRTL EX working fine!
however Compared to UWP, many features do not work properly.
Why do I need to use PInvoke to change the layout, while UWP provides this possibility by changing the language code?

@DarranRowe
Copy link

First and foremost, welcome to the desktop environment. It has a lot of legacy behaviour that, at this point in time, is difficult to change.
Also, when you write "compared to UWP, many features do not work properly", are you sure? Remember, Windows 8 introduced the process model and application type that UWP was based on. This means that the if the default behaviour was changed for the new process model, then "properly" is a relative term. The default LTR window layout, as an example, is the "proper" behaviour in the desktop environment. It is documented in Window Features.
"By default, the window layout is left-to-right (LTR)."
For using P/Invoke to change the layout, I honestly don't know if this is needed. I am a C++ programmer, so this is what I know and was the quickest method to test things. If you are able to find a .NET provided way of mirroring the window layout then use that instead.
For why the desktop environment doesn't support changing the default window mirroring based on setting the process/thread UI languages. This is difficult, but it is definitely behaviour that stems all the way back to Windows 2000 when the multilingual user interface was first introduced. However, the ability to set preferred languages came with Windows Vista. It is possible that this original limitation was due to technical limitations in Windows 2000, it could be that it was just a behaviour decision at that time. The only thing that you can know for sure is that after 23 years, it is unlikely to change now.

The biggest thing you did manage to verify is that WinUI 3 doesn't automatically apply the RTL layout to the underlying desktop window.

@bpulliam bpulliam assigned bpulliam and pratikone and unassigned bpulliam Jul 6, 2023
@soroshsabz
Copy link

ITNOA

But I think WinUI can handle RLT/LTR change layout upper underlying Windows mechanism. and I think WinUI must have all good features and good behavior from UWP. because WinUI (if I understand correctly) wants to replace UWP framework.

@DarranRowe
Copy link

DarranRowe commented Jul 9, 2023

@soroshsabz
The thing to remember here is that, just because the current behaviour is to require setting the layout manually. This doesn't mean that it is intended or desired behaviour in WinUI 3.
Microsoft.UI.Xaml.Window can check the current preferred UI languages and then apply the WS_EX_LAYOUTRTL style to the underlying window if it wants to. This is, IMO, the whole root of the problem. The desktop behaviour is unexpected and it is easy to get caught out if you are used to working with CoreWindow.
We'll see how this is resolved when the issue is closed, however, I would expect that the resolution would only apply to WinUI 3 and not have any surprising effects when applied to a desktop application that uses the Windows App SDK.

@bpulliam bpulliam transferred this issue from microsoft/WindowsAppSDK Aug 10, 2023
@bpulliam bpulliam added team-Reach Issue for the Reach team area-TitleBar Issues related to custom window title bars. labels Aug 10, 2023
@duncanmacmichael duncanmacmichael added the bug Something isn't working label Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-TitleBar Issues related to custom window title bars. bug Something isn't working team-Reach Issue for the Reach team
Projects
None yet
Development

No branches or pull requests

6 participants