XAML MAUI-CollectionView跳转/聚焦到下一个条目

m2xkgtsf  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(346)

我有一个CollectionView,其中的每一项都是一个条目,需要填写一个字符。
我想自动从条目1跳到条目2,以此类推。
如何从CollectionView访问"下一个"条目?以便将焦点设置在下一个条目上?

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp2.RowControlPage"
             xmlns:vm="clr-namespace:MauiApp2.ViewModel"
             Title="RowControlPage">
    <CollectionView>
        <CollectionView.ItemsLayout>
            <LinearItemsLayout Orientation="Horizontal" />
        </CollectionView.ItemsLayout>
        <CollectionView.ItemsSource>
            <x:Array Type="{x:Type vm:CharViewModel}">
                <vm:CharViewModel CharExpected="A" CharTyped="A" CharIndex="1" WordExpected="ABCDEF"/>
                <vm:CharViewModel CharExpected="B" CharTyped="B" CharIndex="2" WordExpected="ABCDEF"/>
                <vm:CharViewModel CharExpected="C" CharTyped="C" CharIndex="3" WordExpected="ABCDEF"/>
                <vm:CharViewModel CharExpected="D" CharTyped="D" CharIndex="4" WordExpected="ABCDEF"/>
                <vm:CharViewModel CharExpected="E" CharTyped="E" CharIndex="5" WordExpected="ABCDEF"/>
                <vm:CharViewModel CharExpected="F" CharTyped="F" CharIndex="6" WordExpected="ABCDEF"/>
            </x:Array>
        </CollectionView.ItemsSource>
        <CollectionView.ItemTemplate>
            <DataTemplate>
                <Entry 
                    Text="{Binding CharExpected}"
                    Name="{Binding CharIndex}"
                    ReturnCommand="{Binding NewCommand}"
                    WidthRequest="70"
                    HeightRequest="70"
                    FontSize="34"
                    Margin="5"
                    Keyboard="Text"
                    HorizontalTextAlignment="Center"
                    VerticalTextAlignment="Center"
                    TextTransform="Uppercase"
                    ReturnType="Send" 
                    MaxLength="1">
                </Entry>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>
</ContentPage>
prdp8dxp

prdp8dxp1#

在您的条目中,只需设置ReturnType=“Next”。MAUI将为您执行此操作:

<Entry 
   Text="{Binding CharExpected}"
   Name="{Binding CharIndex}"
   ReturnCommand="{Binding NewCommand}"
   WidthRequest="70"
   HeightRequest="70"
   FontSize="34"
   Margin="5"
   Keyboard="Text"
   HorizontalTextAlignment="Center"
   VerticalTextAlignment="Center"
   TextTransform="Uppercase"
   ReturnType="Next" 
   MaxLength="1">
</Entry>```

相关问题