Reverse Grid for RightToLeft Languages

DouglasGrossDouglasGross USMember
edited May 2015 in Xamarin.Forms

A certain page of my app is laid out in a Grid. I would like to reverse the Grid horizontally to display properly in RTL languages. Anyone tackled this before?

Answers

  • abdullahtahan.7433abdullahtahan.7433 SAMember ✭✭

    i've the same issue i hope they support rtl :smile:

  • SirAndriySirAndriy USMember ✭✭✭
    edited May 2016

    Hi, I did that with CustomGrid and if IsRightToLeft == true then I reverse grid columns

    `protected override void OnPropertyChanged(string propertyName = null)
    {
    base.OnPropertyChanged(propertyName);
    if ((propertyName == IsRightToLeftProperty.PropertyName && IsRightToLeft != _oldValueOfIsRightToLeft) || (propertyName == ColumnDefinitionsProperty.PropertyName && IsRightToLeft))
    {
    _oldValueOfIsRightToLeft = IsRightToLeft;
    InvertChildren();
    }

            if (propertyName == "Parent" && IsRightToLeft)
            {
                InvertChildren();
            }
        }
    

    private void InvertChildren()
    {
    var columnsCount = ColumnDefinitions.Count;
    if (columnsCount < 2)
    {
    return;
    }

            var cd = ColumnDefinitions.Select(t => t.Width).ToList();
            foreach (var column in ColumnDefinitions)
            {
                var index = ColumnDefinitions.IndexOf(column);
                column.Width = cd[columnsCount - index - 1];
            }
    
            var children = Children.Reverse().ToList();
            foreach (var child in children)
            {
                var index = GetColumn(child);
                SetColumn(child, columnsCount - index - 1);
            }
        }`
    
Sign In or Register to comment.