为CarouselViewControl实现SelectedItem(类似于ListView)
尝试过PositionSelected和PositionSelectedCommand无效,因为它给出了列表中所选项目的位置。
ViewModel实现:
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);
}