Reputation: 383
It is necessary to make the support of Right to Left style (both text and layout-s). I understand that when you set parent Grid
's properties FlowDirection = "RightToLeft"
in all child controls it inherited.
The question is - is there any default setting, which will shift all we need in app? Or should I set every parent greeds FlowDirection
by some king of flag and set this flag as FlowDirection = "RightToLeft"
if we, for example in in Arab countries?
Upvotes: 1
Views: 683
Reputation: 5137
If you are going to support any right to left language will need to have a right to left layout too. You don't need to change FlowDirection property of all of the elements since it is inherited by child elements.
MSDN:
An object inherits the FlowDirection value from its parent in the object tree. Any element can override the value it gets from its parent. If not specified, the default FlowDirection is LeftToRight
So usually you need to set the property once for root element/frame of the Window.
However, some elements like FontIcon and Image does not mirror automatically. FontIcon has a MirroredWhenRightToLeft property:
You can set the MirroredWhenRightToLeft property to have the glyph appear mirrored when the FlowDirection is RightToLeft. You typically use this property when a FontIcon is used to display an icon as part of a control template and the icon needs to be mirrored along with the rest of the control
For Image, you need to flip the image by transforms.
Edit:
You can set the property in the Application class where you create the main frame/page:
// Part of the App.xaml.cs in default UWP project template:
protected override void OnLaunched(LaunchActivatedEventArgs e) {
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached) {
this.DebugSettings.EnableFrameRateCounter = true;
}
#endif
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null) {
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) {
//TODO: Load state from previously suspended application
}
//**********************
// Set flow direction
// *********************
if (System.Globalization.CultureInfo.CurrentCulture.TextInfo.IsRightToLeft) {
rootFrame.FlowDirection = FlowDirection.RightToLeft;
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
...
...
If you don't want to use code behind (I think its OK to use it for this scenario), you can implement IValueConverter (Not recommended):
public class RightToLeftConverter : IValueConverter {
public object Convert(object value, Type targetType,
object parameter, string language) {
if (System.Globalization.CultureInfo.CurrentCulture.TextInfo.IsRightToLeft) {
return FlowDirection.RightToLeft;
}
return FlowDirection.LeftToRight;
}
public object ConvertBack(object value, Type targetType,
object parameter, string language)
{
throw new NotImplementedException();
}
}
and use it in XAML:
<Page
...
...
FlowDirection="{Binding Converter={StaticResource RightToLeftConverter}}">
Upvotes: 3