小编abd*_*dul的帖子

在Button事件处理程序方法Xamarin Forms中获取控件名称

我的Xamarin Forms应用程序中有20个按钮.所有按钮共享相同的单击事件方法.我想要做的是使用switch语句检查按钮名称,但我很难找到触发事件的控件名称.

请看代码:

private  void btnCollection_Clicked(object sender, EventArgs args)
    {
        var btn = (Button)sender;

        switch (btn.FindByName) // I want to get the name of the control 
        {

            case "btn1":
                break;

                case "btn2":
                break;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我怎样才能得到按钮的名字?

c# ios xamarin.forms

5
推荐指数
2
解决办法
8651
查看次数

标签 统计

c# ×1

ios ×1

xamarin.forms ×1