2014-02-28 40 views
0

我想建立的UIBarButtonItem我自己的專業類和我已經這樣做了:IOS xamarin派生類中重寫事件

public class myUIBarButtonItem: UIBarButtonItem { 
UIImage _image { get; set;} 
UIBarButtonItemStyle _style { get; set;} 
string _title { get; set; } 
public myUIBarButtonItem(UIImage mImage,UIBarButtonItemStyle mStyle, string mTitle) 
    : base() 
{ 
_image = mImage; 
_style = mStyle; 
_title = mTitle; 
UITextAttributes myTextAttrib = new UITextAttributes(); 
myTextAttrib.Font = UIFont.FromName("Arial",12); 
myTextAttrib.TextColor = UIColor.FromRGB(202,185,131); 
this.SetTitleTextAttributes (myTextAttrib, UIControlState.Normal); 
this.Image = _image; 
this.Title = _title; 
} 
} 

我會重寫基類的事件,如點擊,我不知道如何處理。一段示例代碼也將對如何使用新事件處理程序使用該類感到欣慰。 在此先感謝。 最大

回答

0

的UIBarButtonItem公開Clicked事件:

Clicked += (object sender, EventArgs e) => { 
    new UIAlertView("Bar button tapped", "", null, "OK", null).Show(); 
}; 
0

它不是通常覆蓋一個事件,所以請提供您爲什麼希望覆蓋更多的相關信息。

如果你想刪除的點擊事件或做些額外的事情存在,你可以用「新」取代它,但我會假設這是不是你所追求的:

public class CustomBarButton : UIBarButtonItem 
{ 
    public new event EventHandler Clicked 
    { 
     add 
     { 
//    base.Clicked += value; 
     } 
     remove 
     { 
//    base.Clicked -= value; 
     } 
    } 
} 
相關問題