How can I get an element with 2 buttons side by side?

北城余情 提交于 2019-12-11 14:21:05

问题


I need to have a Monotouch.Dialog element with 2 buttons side by side using MvvmCross

Has anyone managed this?

I have this so far but know it's not going to work as I have no way of knowing which button was tapped:

public class DoubleButton : Element, IElementSizing{
    UIImage image1;
    UIImage image2;

    public DoubleButton (UIImage image1,UIImage image2, string caption): base(caption)
    {
        this.image1 = image1;
        this.image2 = image2;
    }

    protected override UITableViewCell GetCellImpl (UITableView tv)
    {
        var cell = base.GetCellImpl (tv);
        cell.BackgroundColor = UIColor.Clear;
        cell.SelectionStyle = UITableViewCellSelectionStyle.None;

        var imageView1 = new UIImageView (image1);
        var imageView2 = new UIImageView (image2);

        cell.ContentView.Add (imageView1);
        cell.ContentView.Add (imageView2);
        return cell;
    }

    public float GetHeight (UITableView tableView, NSIndexPath indexPath)
    {
        return 80;
    }
}

回答1:


If you want two buttons and two commands, then you can just add two buttons and two commands - then make the button's trigger the commands.

public class DoubleButton : Element, IElementSizing
{
   UIButton button1;
   UIButton button2;

   public ICommand Command1 { get;set; }
   public ICommand Command2 { get;set; }

   public DoubleButton (UIButton b1,UIButton b2, string caption): base(caption)
   {
       this.button1 = button1;
       this.button2 = button2;

       this.button1.TouchUpInside += (s,e) => { if (Command1 != null) Command1.Execute(null); };
       this.button2.TouchUpInside += (s,e) => { if (Command2 != null) Command2.Execute(null); };
   }

   // ....


来源:https://stackoverflow.com/questions/20550803/how-can-i-get-an-element-with-2-buttons-side-by-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!