首页 > 解决方案 > 为 CarouselViewControl 实现 SelectedItem

问题描述

为 CarouselViewControl 实现 SelectedItem(如在 ListView 上)

尝试过 PositionSelected 和 PositionSelectedCommand 不起作用,因为它给出了列表中所选项目的位置。

视图模型实现:

private void LoadData(IEnumerable<Model> myCourse)
    {
        this.Items.Clear();
        if (myCourse != null)
        {
            foreach (var item in myCourse)
            {
                var itemToAdd = new Model
                {
                    ActiviyId = item.ActiviyId,                        
                };
                Device.BeginInvokeOnMainThread(() =>
                {
                    this.Items.Add(itemToAdd);
                });
            }
        }
    }

    public DelegateCommand<Model> CourseSelectedCommand => new DelegateCommand<Model>(async (Param) => await this.OnCourseItemSelectedCommand(Param));

    private async Task OnCourseItemSelectedCommand(Model model)
    {
        var navigationParams = new NavigationParameters();
        navigationParams.Add("ActivityID", model.ActiviyId);
        await this.navigationService.NavigateAsync("ModulePage", navigationParams, true, false);
    }

标签: xamarin.forms

解决方案


推荐阅读