C# TableView视图单元格点击操作
如何利用ViewCell中的点击操作导航到其他页面 Xmal码C# TableView视图单元格点击操作,c#,xaml,xamarin.forms,C#,Xaml,Xamarin.forms,如何利用ViewCell中的点击操作导航到其他页面 Xmal码 <TableView Intent="Settings" HasUnevenRows="true" VerticalOptions="StartAndExpand" BackgroundColor="White" > <TableRoot> <TableSection> <ViewCell Hei
<TableView Intent="Settings" HasUnevenRows="true" VerticalOptions="StartAndExpand" BackgroundColor="White" >
<TableRoot>
<TableSection>
<ViewCell Height="100" Tapped="OnProfileClicked">
<ViewCell.View>
<StackLayout Orientation="Horizontal" Padding="5,2,5,2" BackgroundColor="White" >
<Image x:Name="ImgProfile" HeightRequest="100"/>
<Label x:Name="btnName" VerticalOptions="Center" TextColor="Black" FontSize="20"/>
<Label Text="> " FontSize="15" HorizontalOptions="EndAndExpand" VerticalOptions="Center"/>
</StackLayout>
</ViewCell.View>
</ViewCell>
</TableSection>
</TableRoot>
</TableView>
因此,您的代码有两个问题 1.)您编写了
Tapped=OnProfileClicked
,但实际创建的方法名为onProfileTapped()
,这是不匹配的
2.)item tapped事件的参数错误,大多数Xamarin事件包含发件人和eventArgs
以下是如何修复代码以使其正常工作:
void OnProfileClicked (object sender, System.EventArgs e) { //your code}
另外,当您使用导航推送页面时,提示。您可能希望将该方法标记为异步,并等待操作以确保平稳过渡。谢谢您的回复。我已经更改了添加async和Wait操作的代码,但是,它确实会提示此错误消息“Method OnProfileClicked没有正确的签名”。我认为我提供的args类型是错误的。尝试在ProfileClicked上作废(对象发送者,System.EventArgs e)。我编辑了解决方案,试一试。
void OnProfileClicked (object sender, System.EventArgs e) { //your code}