Right to left(RTL) in Xamarin TreeView (SfTreeView)

11 Apr 20242 minutes to read

TreeView supports to change the flow of text to the right-to-left direction by setting the FlowDirection to RightToLeft. TreeView supports RTL in Xamarin.Forms version 3.0 and above.

NOTE

Specific platform setup is required to enable right-to-left localization. For platform settings you can refer here.

<ContentPage  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
              xmlns:syncfusion="clr-namespace:Syncfusion.XForms.TreeView;assembly=Syncfusion.SfTreeView.XForms">
    <ContentPage.Content>
       <syncfusion:SfTreeView x:Name="treeView" FlowDirection="RightToLeft"/>
    </ContentPage.Content>
</ContentPage>
treeView.FlowDirection = FlowDirection.RightToLeft;

TreeView also supports RTL when device’s flow direction is changed, it is achieved by setting the FlowDirection to Device.FlowDirection.

<ContentPage  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
              xmlns:syncfusion="clr-namespace:Syncfusion.XForms.TreeView;assembly=Syncfusion.SfTreeView.XForms">
    <ContentPage.Content>
       <syncfusion:SfTreeView x:Name="treeView" FlowDirection="{x:Static Device.FlowDirection}"/>
    </ContentPage.Content>
</ContentPage>
treeView.FlowDirection = Device.FlowDirection;

In UWP platform, the ScrollView is not changed when RTL is enabled (framework issue). To overcome this issue, set the FlowDirection property in constructor of MainPage in UWP renderer as demonstrated in the following code example.

public MainPage()
{
    
    SfTreeViewRenderer.Init();
    this.FlowDirection = FlowDirection.RightToLeft;
    LoadApplication (new App ());
    
}

Download the entire source code from GitHub here.

Xamarin Forms TreeView with right to left

NOTE

When a label is loaded in the ItemTemplate, the right-to-left direction is not applied due to the framework issue. It has been reported to the Xamarin team; for more details about this, refer to this link. To overcome this issue, set the HorizontalOptions to StartAndExpand in Label.

Limitations

  • When you use custom ItemTemplate in TreeView, it does not respond to FlowDirection due to framework issue. To respond to FlowDirection changes, you need to set FlowDirection of TreeView to parent view of your custom ItemTemplate.

See also

How to work with RTL in Xamarin.Forms TreeView (SfTreeView)