【问题标题】:TableView Viewcell Tapped actionTableView Viewcell 点击操作
【发布时间】:2016-07-13 15:46:11
【问题描述】:

如何利用 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());
    }

【问题讨论】:

    标签: c# xaml xamarin.forms


    【解决方案1】:

    所以你的代码有一些问题。

    1.) 你写了Tapped=OnProfileClicked,但你实际做的方法叫onProfileTapped(),这是不匹配

    2.) 您的项目点击事件的参数是错误的,大多数 Xamarin 事件都包含发送者和 eventArgs。

    以下是修复代码以使其正常工作的方法:

    void OnProfileClicked (object sender, System.EventArgs e) { //your code}
    

    另外,提示,当您使用导航推送页面时。您可能希望将该方法标记为异步并等待该操作以确保其平滑过渡。

    【讨论】:

    • 感谢您的回复。我已经更改了添加异步和等待操作的代码,但是它确实提示此错误消息“方法 OnProfileClicked 没有正确的签名”。
    • 我认为我给的 args 类型是错误的。尝试 void OnProfileClicked(object sender, System.EventArgs e)。我编辑了解决方案,试一试。
    猜你喜欢
    • 2017-05-07
    • 2020-07-04
    • 2018-02-01
    • 2021-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    • 2020-02-05
    相关资源
    最近更新 更多