2013-12-12 68 views
0

我需要一個Monotouch.Dialog元素並排使用2個按鈕使用MvvmCross如何獲得帶有2個並排按鈕的元素?

有沒有人管理這麼?

我有這到目前爲止,但知道這行不通,因爲我有沒有辦法知道哪個按鈕被竊聽:

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

如果你想兩個按鈕和兩個命令,那麼你可以添加兩個按鈕和兩個命令 - 然後使按鈕的觸發命令。

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

    // .... 
+0

這個工作就像一個魅力 – iwayneo

+0

這是我實現:https://gist.github.com/wayne-o/8002890 – iwayneo

+0

和用法示例:https://gist.github.com/wayne-o/8002925 – iwayneo

相關問題