【问题标题】:How to trigger method in Children ImageButton in Xamarin?如何在 Xamarin 中的儿童 ImageButton 中触发方法?
【发布时间】:2021-04-10 04:24:55
【问题描述】:

我创建了 ImageButton,StackLayout 的子项,我想通过单击它来激活删除方法。我不能使用“点击”,所以我不知道该怎么做。

Content = new StackLayout
                    {
                        Children =
                        {                                
                            new ImageButton {Source = "/drawable/delete", HorizontalOptions = LayoutOptions.End, HeightRequest = 60, BackgroundColor = Color.Red, Padding = new Thickness(20,-5), CornerRadius = 45}
                        }
                    }

【问题讨论】:

    标签: c# xamarin imagebutton


    【解决方案1】:

    你可以使用TapGestureRecognizer

    
    var imagebutton = new ImageButton {Source = "/drawable/delete", HorizontalOptions = LayoutOptions.End, HeightRequest = 60, BackgroundColor = Color.Red, Padding = new Thickness(20,-5), CornerRadius = 45} 
    
    var tapGestureRecognizer = new TapGestureRecognizer();
    tapGestureRecognizer.Tapped += (s, e) => {
        // handle the tap
    };
    imagebutton .GestureRecognizers.Add(tapGestureRecognizer);
    
    
    Content = new StackLayout
                        {
                            Children =
                            {                                
                                imagebutton 
                            }
                        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多