【问题标题】:How can I get an element with 2 buttons side by side?如何获得并排有 2 个按钮的元素?
【发布时间】:2013-12-12 18:00:14
【问题描述】:

我需要一个使用 MvvmCross 并排有 2 个按钮的 Monotouch.Dialog 元素

有人处理过这个吗?

到目前为止我有这个,但知道它不会起作用,因为我无法知道点击了哪个按钮:

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;
    }
}

【问题讨论】:

    标签: xamarin.ios xamarin mvvmcross monotouch.dialog


    【解决方案1】:

    如果你想要两个按钮和两个命令,那么你可以添加两个按钮和两个命令 - 然后让按钮触发命令。

    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); };
       }
    
       // ....
    

    【讨论】:

    • 我的解决方案似乎有缺陷,因为引用 ICommand 似乎称之为:/ 这样做的最佳方法是什么?
    猜你喜欢
    • 2011-07-29
    • 1970-01-01
    • 2011-01-16
    • 2011-12-25
    • 2020-08-12
    • 1970-01-01
    • 2019-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多