2017-03-08 56 views
0

我只是想知道:沒有事件處理窗口在Visual Studio Xamarin

當我的代碼在WPF C#我在Propertie窗口的GUI元素的事件,一個小按鈕
和我可以雙擊它所以它會生成一個事件。

喜歡的東西:

private void Button_Click(object sender, RoutedEventArgs e) 
    { 

    } 

http://i.imgur.com/u0oRu5g.png(閃光燈圖標的右上角)

如果我在Visual Studio C#創建Xamarin的Android項目,我只是得到一個屬性窗口。無尼斯和快速自動事件生成:(

https://i.imgur.com/fs6MVeN.png(只是屬性)

問:請問操作窗口簡單的犯規在Xamarin的Visual Studio C#存在(我認爲Xamarin IOS,你可以做到這一點)。 。 Visual Studio的汽車可以產生Xamarin事件處理在某些方面,我還是必須用手工代碼,他們每一個人

謝謝您的幫助

回答

1

問題:?!是否操作窗口根本不存在Xamarin Visual Studio C#中。 (我認爲在Xamarin IOS你可以做到這一點)。 Visual Studio能否以某種方式自動爲Xamarin生成事件處理程序,還是必須用手對它們中的每一個進行編碼?

當前VS無法在Xamarin Designer中生成事件處理程序。就我個人而言,我也對編碼事件處理程序感到痛苦。但後來我發現了一種快速生成在編輯器中的事件處理程序,可能會有所幫助:

  1. 在你的活動OnCreate方法找到目標元素:

    protected override void OnCreate(Bundle bundle) 
    { 
        base.OnCreate(bundle); 
        SetContentView (Resource.Layout.Main); 
    
        var button = FindViewById<Button>(Resource.Id.btnClick); 
    } 
    
  2. 代碼button.Click+=然後按tab鍵盤上:

    protected override void OnCreate(Bundle bundle) 
    { 
        base.OnCreate(bundle); 
        SetContentView (Resource.Layout.Main); 
    
        var button = FindViewById<Button>(Resource.Id.btnClick); 
        button.Click+= //press 'tab' now 
    } 
    
  3. VS將生成的事件處理程序,那麼:

    protected override void OnCreate(Bundle bundle) 
    { 
        base.OnCreate(bundle); 
        SetContentView (Resource.Layout.Main); 
    
        var button = FindViewById<Button>(Resource.Id.btnClick); 
        button.Click += Button_Click; 
    } 
    
    private void Button_Click(object sender, System.EventArgs e) 
    { 
        throw new System.NotImplementedException(); 
    } 
    
+0

非常感謝您對此提示! (它現在不那麼痛苦了:D 我希望微軟有一天會在Visual Studio中添加這個功能 – Kopfsalat