how to make your controls stick to the same place if language is changed to RTL while app is running MAUI

huangapple go评论65阅读模式
英文:

how to make your controls stick to the same place if language is changed to RTL while app is running MAUI

问题

AppInfo.RequestedLayoutDirection 在应用运行时更改语言为 RTL 后不会更新,只有在重新启动应用程序时才会更新。

我希望我的应用程序无论设备的布局方向如何都不会改变外观,目前如果布局方向更改,所有东西都会倒置,例如:列 0 变为列 2 或 translationX 完全反转。

我尝试通过其他方式查找此信息,比如检查语言是否已更改,但直到重新启动应用程序时它才会更改。

有没有办法在不重新启动应用程序的情况下获得更新后的 LayoutDirection?或者有其他方法使控件始终保持在相同的位置?

英文:

AppInfo.RequestedLayoutDirection doesnt update if you change language to RTL while app is running only when its restarted.

i want my app to not change appearance no matter what layout direction the device is , right now everything gets inverted if layout direction is changed, for example : column 0 becomes column 2 or translationX gets completely reversed.

i've tried finding this info through other means like check to see if language has changed, but that one doesnt change either until app is restarted .

is there anyway to get it to give you the updated LayoutDirection without restarting the app? or other ways to make your controls stick to the same place no matter what?

答案1

得分: 2

您可以将FlowDirection设置为ContentPage或您想要更改方向的任何控件:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="ControlsRTL75712428.MainPage"
         FlowDirection="LeftToRight">


或

<VerticalStackLayout FlowDirection="RightToLeft"
        Spacing="25"
        Padding="30,0"
        VerticalOptions="Center">

然后,无论语言如何更改,控件都将保持在指定的方向上。

希望对您有帮助。
英文:

You could set FlowDirection to ContentPage or any control you want to change the directioin:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="ControlsRTL75712428.MainPage"
         FlowDirection="LeftToRight">

or

<VerticalStackLayout FlowDirection="RightToLeft"
        Spacing="25"
        Padding="30,0"
        VerticalOptions="Center">

Then the control will stick to the direction no matter the language changes.

Hope it works for you.

huangapple
  • 本文由 发表于 2023年3月12日 18:14:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75712428.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定