Skip to content

RTL support #21

Closed
Closed

Description

@hichamboushaba

FlowDirection is not supported yet, when do you plan to add it to support RTL in all platforms.

Activity

  1. added
    kind/enhancement
    on Jun 26, 2018
  2. added
    area/a11y
    on Oct 17, 2019
  3. added
    project/layout 🧱
    on Sep 21, 2020
  4. added
    difficulty/tbd
    on Feb 15, 2021
  5. Arlodotexe commented on Mar 25, 2021

    @Arlodotexe
    Contributor

    Also curious about this, low priority but something we'd like to support in our app.

  6. added
    difficulty/medium 🤔
    and removed
    difficulty/tbd
    on May 31, 2021
  7. 12 remaining items

  8. balbarak commented on Aug 11, 2023

    @balbarak

    Any update.

    This feature is very important for RTL languages and speakers

  9. balbarak commented on Sep 4, 2023

    @balbarak

    @Youssef1313 @MartinZikmund

    Hello, I did some attached property that do the job maybe will give you a starting point here is the code

    controls that reversed are StackPanel Grid TextBox TextBlock FrameworkElement Control

            private static void ChangeDirection(UIElement element, ElementFlowDirection dir)
            {
                var grids = new List<Grid>();
                var stackPanels = new List<StackPanel>();
                var frameWorkElements = new List<FrameworkElement>();
                var textBlocks = new List<TextBlock>();
                var textBoxes = new List<TextBox>();
                var controls = new List<Control>();
    
                UIElementHelper.FindChildren(grids, element);
                UIElementHelper.FindChildren(stackPanels, element);
                UIElementHelper.FindChildren(frameWorkElements, element);
                UIElementHelper.FindChildren(textBlocks, element);
                UIElementHelper.FindChildren(textBoxes, element);
                UIElementHelper.FindChildren(controls, element);
    
                grids.ForEach(ReverseGridChilds);
                stackPanels.ForEach(ReverseStackPanel);
                frameWorkElements.ForEach(ReverseMarginsAndHorizontalAlignment);
                textBoxes.ForEach(ReverseTextBoxes);
                textBlocks.ForEach(ReverseTextBlock);
                controls.ForEach(ReversePadding);
            }
    
            private static void ReverseGridChilds(Grid grid)
            {
                var childs = grid.Children;
    
                var colCount = grid.ColumnDefinitions.Count;
    
                var colDefs = grid.ColumnDefinitions.ToList();
    
                colDefs = Enumerable.Reverse(colDefs).ToList();
    
                grid.ColumnDefinitions.Clear();
    
                foreach (var item in colDefs)
                {
                    grid.ColumnDefinitions.Add(item);
                }
    
                if (colCount <= 0)
                    return;
    
                var array = Enumerable.Range(0, colCount).ToArray();
                array = Enumerable.Reverse(array).ToArray();
    
                foreach (var item in childs)
                {
                    var frame = item as FrameworkElement;
    
                    var colNo = Grid.GetColumn(frame);
                    var colSpan = Grid.GetColumnSpan(frame);
    
                    if (colNo > array.Length - 1)
                        continue;
    
                    int targetVale = array[colNo];
    
                    if (colSpan > 1)
                    {
                        Grid.SetColumnSpan(frame, colSpan);
    
                        int targetValue = targetVale / colSpan;
    
                        Grid.SetColumn(frame, targetValue);
                    }
                    else
                    {
                        Grid.SetColumn(frame, targetVale);
                    }
                }
            }
    
            private static void ReverseStackPanel(StackPanel panel)
            {
                if (panel.Orientation != Orientation.Horizontal)
                    return;
    
                var childs = panel.Children.ToArray();
    
                childs = Enumerable.Reverse(childs).ToArray();
    
                panel.Children.Clear();
    
                foreach (var item in childs)
                {
                    panel.Children.Add(item);
                }
            }
    
            private static void ReverseMarginsAndHorizontalAlignment(FrameworkElement element)
            {
                var top = element.Margin.Top;
                var bottom = element.Margin.Bottom;
                var left = element.Margin.Left;
                var right = element.Margin.Right;
    
                element.Margin = new Thickness(right, top, left, bottom);
    
                if (element.HorizontalAlignment == HorizontalAlignment.Left)
                {
                    element.HorizontalAlignment = HorizontalAlignment.Right;
                }
                else if (element.HorizontalAlignment == HorizontalAlignment.Right)
                {
                    element.HorizontalAlignment = HorizontalAlignment.Left;
                }
            }
    
            private static void ReversePadding(Control element)
            {
                var top = element.Padding.Top;
                var bottom = element.Padding.Bottom;
                var left = element.Padding.Left;
                var right = element.Padding.Right;
    
                element.Padding = new Thickness(right, top, left, bottom);
            }
    
            private static void ReverseTextBoxes(TextBox textBox)
            {
                var alignment = textBox.TextAlignment;
    
                var shouldNotChanged = alignment == TextAlignment.Center || alignment == TextAlignment.Justify;
    
                if (shouldNotChanged)
                    return;
    
                var isLeft = alignment == TextAlignment.Left || alignment == TextAlignment.Start;
                var isRight = alignment == TextAlignment.Right || alignment == TextAlignment.End;
    
    
    #if ANDROID
                textBox.TextAlignment = TextAlignment.Start;
                if (textBox.LayoutDirection == Android.Views.LayoutDirection.Ltr)
                {
                    textBox.LayoutDirection = Android.Views.LayoutDirection.Rtl;
                    textBox.TextDirection = Android.Views.TextDirection.Rtl;
                }
                else
                {
                    textBox.LayoutDirection = Android.Views.LayoutDirection.Ltr;
                    textBox.TextDirection = Android.Views.TextDirection.Ltr;
                }
    #else
    
                if (isLeft)
                {
                    textBox.TextAlignment = TextAlignment.Right;
                }
                else if (isRight)
                {
                    textBox.TextAlignment = TextAlignment.Left;
                }
    #endif
            }
    
            private static void ReverseTextBlock(TextBlock text)
            {
                var textAlignment = text.TextAlignment;
    
                var isLeft = textAlignment == TextAlignment.Left;
                var isRight = textAlignment == TextAlignment.Right;
    
    #if ANDROID
                text.TextAlignment = TextAlignment.Start;
    
                if (text.LayoutDirection == Android.Views.LayoutDirection.Ltr)
                {
                    text.LayoutDirection = Android.Views.LayoutDirection.Rtl;
                    text.TextDirection = Android.Views.TextDirection.Rtl;
                }
                else
                {
                    text.LayoutDirection = Android.Views.LayoutDirection.Ltr;
                    text.TextDirection = Android.Views.TextDirection.Ltr;
                }
    #else
                if (isLeft)
                {
                    text.TextAlignment = TextAlignment.Right;
    
                }
                else if (isRight)
                {
                    text.TextAlignment = TextAlignment.Left;
                }
    #endif
    
            }
        }
  10. MartinZikmund commented on Sep 5, 2023

    @MartinZikmund
    Member

    @balbarak thank you a lot! We will try to prioritize this as soon as possible!

  11. Youssef1313 commented on Sep 6, 2023

    @Youssef1313
    Member

    Thanks @balbarak.

    Opened #13524 to support that on Skia.

    There are some specific elements that shouldn't probably inherit FlowDirection

    • Image
    • WebView
    • MediaPlayerElement

    After getting #13524 merged, I'll work on getting this for other platforms plus handle the specific elements that don't inherit FlowDirection.

  12. self-assigned this
    on Sep 6, 2023
  13. added theissue type on Jun 24, 2025
  14. Youssef1313 commented on Jul 18, 2025

    @Youssef1313
    Member

    @MartinZikmund FYI, this is mostly done on Skia. There is some special casing that will still be needed for Image/WebView/MPE. This is how it's done in WinUI:

    https://github.com/microsoft/microsoft-ui-xaml/blob/2aa50f0dff795cbd948588ee0e62cac7da3a396f/src/dxaml/xcp/core/core/elements/mediabase.cpp#L353-L367

    It will be worth ensuring the following scenarios work as expected:

    • Image, WebView, MPE
    • Moving focus with keyboard (both using tab and arrow keys)
    • TextBox

    After that, you can close it if you are not interested in native renderers.

  15. MartinZikmund commented on Jan 22, 2026

    @MartinZikmund
    Member

    This is now mostly supported on Skia targets, let's open new issues for anything that is missing

  16. github-actions commented on Apr 30, 2026

    @github-actions
    Contributor

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or feature requests.

  17. locked as resolved and limited conversation to collaborators on Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/a11ydifficulty/challenging 🤯epickind/enhancementproject/layout 🧱

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions