Maui for android LTR RTL modes problem

Haviv Elbsz 1,886 Reputation points
2023-03-10T12:50:01.7066667+00:00

This is a complete code that show my issue


Hello when runnig this this app the swich to RTL mode its not set focus
and not show caret cursor. but for LTR mode its work OK
how I fix this Thank you.


MainPage.xaml file
------------------


<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="LTR_RTL_Switch.MainPage" 
             FlowDirection="LeftToRight" BackgroundColor="#107e71" >

    <ScrollView x:Name="topscroll">

        <VerticalStackLayout x:Name="vLayout" Margin="10" Padding="5" Spacing="5" BackgroundColor="#ECE5DD" >
            
            <HorizontalStackLayout >
 



               <CheckBox x:Name="L2RAlfaBetCKB" IsChecked="False"
                    CheckedChanged="L2RAlfaBetCKB_CheckedChanged"
                    HorizontalOptions="Center" VerticalOptions="Center" />

                <Label Text="Checked = RightToLeft Writing" FontAttributes="Bold"
                    HorizontalOptions="Start" VerticalOptions="Center" />
            </HorizontalStackLayout>

            <Border  StrokeThickness="1" Stroke="#107e71" >

                <ScrollView x:Name="editscroll" Orientation="Vertical" HeightRequest="400"
                   BackgroundColor="LightBlue" VerticalScrollBarVisibility="Always" >

                    <ScrollView Orientation="Horizontal" HorizontalScrollBarVisibility="Always" >

                        <Editor x:Name="InputTB"
                           FontSize="18" FlowDirection="LeftToRight"
                           AutoSize="TextChanges" TextChanged="InputTB_TextChanged"
                           IsSpellCheckEnabled="False"
                           FontAttributes="Bold" IsTextPredictionEnabled="False"
                           FontFamily="NCourier" 
                           MinimumWidthRequest="-1" >
                        </Editor>

                    </ScrollView>
                </ScrollView>

            </Border>

            <Label
                Text="Welcome to .NET Multi-platform App UI"
                SemanticProperties.HeadingLevel="Level2"
                SemanticProperties.Description="Welcome to dot net Multi platform App U I"
                FontSize="18"
                HorizontalOptions="Center" />

            <Button
                x:Name="CounterBtn"
                Text="Click me"
                SemanticProperties.Hint="Counts the number of times you click"
                Clicked="OnCounterClicked"
                HorizontalOptions="Center" />

        </VerticalStackLayout>
        
    </ScrollView>

</ContentPage>


MainPage.xaml.cs file
---------------------

namespace LTR_RTL_Switch;

public partial class MainPage : ContentPage
{
	int count = 0;
    bool bL2RAflipping = false;

    public MainPage()
	{
	  InitializeComponent();
	  //InputTB.Focus();
    }

	private void OnCounterClicked(object sender, EventArgs e)
	{
		count++;

		if (count == 1)
			CounterBtn.Text = $"Clicked {count} time";
		else
			CounterBtn.Text = $"Clicked {count} times";

		SemanticScreenReader.Announce(CounterBtn.Text);
	}

  //-----------------------------------------------------------------------------

   private void MainPage_Loaded(object sender, EventArgs e)
   {
     InputTB.Focus();
   }

  //-----------------------------------------------------------------------------

  private void L2RAlfaBetCKB_CheckedChanged(object sender, CheckedChangedEventArgs e)
  {

    if (L2RAlfaBetCKB.IsChecked == true)
    {
        bL2RAflipping = true;
        InputTB.FlowDirection = FlowDirection.RightToLeft;
    }
    else
    {
      bL2RAflipping = false;
      InputTB.FlowDirection = FlowDirection.LeftToRight;
    }

    InputTB.Focus();
  }

    //-----------------------------------------------------------------------------



    //private void L2RAlfaBetCKB_CheckedChanged(object sender, CheckedChangedEventArgs e)
    //{

    //}

    private void InputTB_TextChanged(object sender, TextChangedEventArgs e)
	{

    }
}




.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,842 questions
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 35,021 Reputation points Microsoft Vendor
    2023-03-13T05:57:13.8466667+00:00

    Hello,

    After my tests, the cause of this issue is the AutoSize property, and RTL works fine after removing this property.

    <Editor x:Name="InputTB"
        FontSize="18" FlowDirection="LeftToRight"
        TextChanged="InputTB_TextChanged"
        IsSpellCheckEnabled="False"
        FontAttributes="Bold" IsTextPredictionEnabled="False"
        FontFamily="NCourier" 
        MinimumWidthRequest="-1" >
    </Editor>
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful