Windows 上的 InputView 阅读顺序

这种通用 Windows 平台特有的功能可动态检测 EntryEditorLabel 实例中双向文本的阅读顺序(从左到右或从右到左)。 在 XAML 中,可通过将 InputView.DetectReadingOrderFromContent(对于 EntryEditor 实例)或 Label.DetectReadingOrderFromContent 附加属性设置为 boolean 值来使用它:

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

或者,可以使用 Fluent API 从 C# 使用它:

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

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

Editor.On<Windows> 方法指定此项平台特定功能仅在通用 Windows 平台上运行。 Xamarin.Forms.PlatformConfiguration.WindowsSpecific 命名空间中的 InputView.SetDetectReadingOrderFromContent 方法用于控制是否从 InputView 中的内容中检测读取顺序。 此外,InputView.SetDetectReadingOrderFromContent 方法可用于通过调用 InputView.GetDetectReadingOrderFromContent 方法返回当前值来切换是否从内容中检测读取顺序:

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

结果是,EntryEditorLabel 实例可以动态检测其内容的阅读顺序:

InputView 检测特定于平台的内容的阅读顺序

注意

与设置 FlowDirection 属性不同,从其文本内容中检测读取顺序的视图的逻辑不会影响视图中文本的对齐方式。 相反,它会调整双向文本块的布局顺序。