以编程方式关注Listview中的下一个条目(UWP,Xamarin.Forms)

时间:2017-11-16 11:08:59

标签: c# listview xamarin.forms uwp

我有以下xaml:

<ListView x:Name="ListViewItemPage" ItemTapped="ListView_OnItemTapped" >
    <ListView.ItemTemplate>
        <DataTemplate x:Name="DataTemplate">
            <ViewCell>
                <RelativeLayout x:Name="RelativeLayout" >
                    <Label x:Name="DescriptionLabel" Text="{Binding Description}" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=15}" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=X, Factor=0, Constant=15}" />
                    <Entry x:Name="ValueEntry" WidthRequest="85" Keyboard="Text" HorizontalTextAlignment="Start" FontSize="19" HorizontalOptions="Center" VerticalOptions="Center" Text="{Binding Value, Mode=TwoWay, Converter={StaticResource FloatValueConverter}}" Focused="ValueEntry_OnFocused" Unfocused="ValueEntry_OnUnfocused" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=10}" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant={StaticResource ConstantMultiPlatform}}" >
                        <Entry.HeightRequest>
                            <OnPlatform x:TypeArguments="x:Double">
                                <On Platform="iOS" Value="28"></On>
                                <On Platform="Android" Value="42"></On>
                                <On Platform="UWP" Value="32"></On>
                            </OnPlatform>
                        </Entry.HeightRequest>
                    </Entry>
                </RelativeLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

在代码中,我正在使用这种方法。在Android / IOS上它运行良好,但在UWP上它不起作用。

public async Task GetFocusOnNextEntry()
{
    var focused = (CollectionItemValues)focusedEntry.BindingContext;

    var index = _obserColItemValues.IndexOf(focused);

    var nextEntry = (Entry)ListViewItemPage.TemplatedItems[index + 1].LogicalChildren[0].LogicalChildren[1];
    nextEntry.Focus();
}

如何将选定条目中的UWP Xamarin Forms App(便携版)专注于Listview中的下一个条目?

0 个答案:

没有答案