如何利用ViewCell中的Tapped操作导航到其他页面?
Xmal代码
<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>
CS档案
public void onProfileTapped()
{
Navigation.PushAsync(new Clubs());
}
答案 0 :(得分:1)
所以你的代码有一些问题。
1。)你写了Tapped=OnProfileClicked
,但你实际制作的方法叫做onProfileTapped()
,这是不匹配的
2。)项目点击事件的参数错误,大多数Xamarin事件包含sender和eventArgs。
以下是修改代码以使其正常工作的方法:
void OnProfileClicked (object sender, System.EventArgs e) { //your code}
另外,当您使用Navigation推送页面时,请提示。您可能希望将该方法标记为异步并等待操作以确保它是平滑过渡。