Share via


InputView Reading Order on Windows

This Universal Windows Platform platform-specific enables the reading order (left-to-right or right-to-left) of bidirectional text in Entry, Editor, and Label instances to be detected dynamically. It's consumed in XAML by setting the InputView.DetectReadingOrderFromContent (for Entry and Editor instances) or Label.DetectReadingOrderFromContent attached property to a boolean value:

<ContentPage ...
             xmlns:windows="clr-namespace:Xamarin.Forms.PlatformConfiguration.WindowsSpecific;assembly=Xamarin.Forms.Core">
    <StackLayout>
        <Editor ... windows:InputView.DetectReadingOrderFromContent="true" />
        ...
    </StackLayout>
</ContentPage>

Alternatively, it can be consumed from C# using the fluent API:

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.WindowsSpecific;
...

editor.On<Windows>().SetDetectReadingOrderFromContent(true);

The Editor.On<Windows> method specifies that this platform-specific will only run on the Universal Windows Platform. The InputView.SetDetectReadingOrderFromContent method, in the Xamarin.Forms.PlatformConfiguration.WindowsSpecific namespace, is used to control whether the reading order is detected from the content in the InputView. In addition, the InputView.SetDetectReadingOrderFromContent method can be used to toggle whether the reading order is detected from the content by calling the InputView.GetDetectReadingOrderFromContent method to return the current value:

editor.On<Windows>().SetDetectReadingOrderFromContent(!editor.On<Windows>().GetDetectReadingOrderFromContent());

The result is that Entry, Editor, and Label instances can have the reading order of their content detected dynamically:

InputView detecting reading order from content platform-specific

Note

Unlike setting the FlowDirection property, the logic for views that detect the reading order from their text content will not affect the alignment of text within the view. Instead, it adjusts the order in which blocks of bidirectional text are laid out.