Xamarin.Forms Content of a button

后端 未结 6 1047
我寻月下人不归
我寻月下人不归 2021-02-15 16:13

I\'m trying to add a custom content to a button in Xamarin Forms.

By default Button is created like this:

6条回答
  •  暖寄归人
    2021-02-15 16:46

    Thanks Paul,

    I have created my own UserControl which handles that

    Here it is:

    public partial class ContentButton : ContentView
    {
        public ContentButton()
        {
            InitializeComponent();
        }
    
        public event EventHandler Tapped;
    
        public static readonly BindableProperty CommandProperty = BindableProperty.Create(c => c.Command, null);
    
        public ICommand Command
        {
            get { return (ICommand)GetValue(CommandProperty); }
            set { SetValue(CommandProperty, value); }
        }
    
        private void TapGestureRecognizer_OnTapped(object sender, EventArgs e)
        {
            if(Tapped != null)
                Tapped(this,new EventArgs());
        }
    }
    

    And view code:

    
    
      
        
      
    
    
    

提交回复
热议问题