Xamarin XAML ListView-如何以编程方式选择 [英] Xamarin XAML ListView - How to select programmatically

查看:91
本文介绍了Xamarin XAML ListView-如何以编程方式选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xamarin开发Windows Mobile应用程序,但似乎无法以编程方式设置所选的ListView项.

I am developing a windows mobile application with Xamarin, but don't seem to be able to programmatically set the selected ListView item.

我尝试了以下ListViews方法,但仍然没有任何操作

I have tried the following ListViews methods and still nothing

SelectedItem
ScrollTo()
Focus()

我也用谷歌搜索,似乎没什么可说的. 我该怎么办?

I have also googled it and can't seem anything to say how to do this. How do I do this?

推荐答案

在我的示例应用程序中,该方法工作正常:

This works fine in my sample app:

public partial class ItemsPage : ContentPage
{
    public ItemsPage()
    {
        InitializeComponent();
        Vm = new ItemsViewModel();
        BindingContext = Vm;
    }

    protected override void OnAppearing()
    {
        ListviewItems.SelectedItem = Vm.Items[1];
    }

    public ItemsViewModel Vm { get; private set; }

在我的示例应用程序中,ItemsViewModel.ItemsList<string>.

In my sample app, ItemsViewModel.Items is a List<string>.

此行代码在OnAppearing中运行后,将选择列表中的第二项.

The second item in the list is set selected after this line of code runs in OnAppearing.

这篇关于Xamarin XAML ListView-如何以编程方式选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆