Xamarin.forms 如何在列表视图中点击项目并将其发送到其他页面
嗨,我是xamarin forms的新手,我做了一些工作,但在谷歌上找不到太多Xamarin.forms 如何在列表视图中点击项目并将其发送到其他页面,xamarin.forms,Xamarin.forms,嗨,我是xamarin forms的新手,我做了一些工作,但在谷歌上找不到太多 我有一个类帐户,它在列表视图中显示一个列表,如果有人能提供帮助,我希望点击该项目并在另一个页面中显示该项目的更多详细信息这是一个很好的起点 ListView支持一次选择一个项目。默认情况下,选择处于启用状态。当用户点击一个项目时,会触发两个事件:ItemTapped和ItemSelected。请注意,两次点击同一项不会触发多个ItemSelected事件,但会触发多个ItemTapped事件。还请注意,如果取消选择某
我有一个类帐户,它在列表视图中显示一个列表,如果有人能提供帮助,我希望点击该项目并在另一个页面中显示该项目的更多详细信息这是一个很好的起点 ListView支持一次选择一个项目。默认情况下,选择处于启用状态。当用户点击一个项目时,会触发两个事件:ItemTapped和ItemSelected。请注意,两次点击同一项不会触发多个ItemSelected事件,但会触发多个ItemTapped事件。还请注意,如果取消选择某个项目,将调用ItemSelected 请注意,取消选择项目和选择项目时都会调用ItemSelected。这意味着您需要在ItemSelected事件处理程序中检查null SelectedItem,然后才能使用它:
void OnSelection (object sender, SelectedItemChangedEventArgs e)
{
if (e.SelectedItem == null) {
return; //ItemSelected is called on deselection, which results in SelectedItem being set to null
}
DisplayAlert ("Item Selected", e.SelectedItem.ToString (), "Ok");
//((ListView)sender).SelectedItem = null; //uncomment line if you want to disable the visual selection state.
}
如果你想推一个页面,你可以
Navigation.PushAsync(new MyPage(e.SelectedItem));
**对点击的列表项使用ItemSelected事件,如下所示**
//在这里实现代码
在.cs文件中:
public void播放视频(对象发送者,选择EditemChangedEventArgs e)
{
TestList testView=newtestlist();
Navigation.PushAsync(testView);
}
我认为一些代码会有所帮助。
**Use ItemSelected event for list item tapped,like this**
<ListView ItemsSource="{Binding TopicList}" HasUnevenRows="True" ItemSelected="PlayVideo">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
//implement code here
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
On .cs file:
public void PlayVideo(object sender, SelectedItemChangedEventArgs e)
{
TestList testView = new TestList();
Navigation.PushAsync(testView);
}