2017-03-08 62 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