简体   繁体   English

如何在Xamarin.Forms中添加/生成按钮单击事件

[英]How to Add/Generate a button click event in Xamarin.Forms

I am developing Xamarin forms project, I have added button on one of my Xaml page but I am not able to generate click event for this button but Visual studio is not showing any intellisense. 我正在开发Xamarin表单项目,我在Xaml页面之一上添加了按钮,但是我无法为此按钮生成click事件,但是Visual Studio没有显示任何intellisense。

I have read in another post that suggest installing Resharper for this issue but it is not feasible for me because I do not have installation permission. 我在另一篇文章中读过,建议针对此问题安装Resharper,但由于我没有安装权限,因此对我而言不可行。

I am using Visual Studio Enterprise edition 2017. 我正在使用Visual Studio Enterprise版本2017。

Working with Intellisense 使用Intellisense

In VisualStudio ctrl+space to kick intellisense. 在VisualStudio的Ctrl + Space上启动智能感知。 Move your cursor right between the quotes, as seen in the image below, and hit ctrl+space. 如下图所示,将光标右移至引号之间,然后按ctrl + space。 Intellisense should pop up now suggesting to create an event handler. 现在应该弹出Intellisense,建议创建事件处理程序。

XAML事件的图像

Manual Solution 手动解决方案

In general you could use the Xamarin documentation to find out how the event handler method should look like. 通常,您可以使用Xamarin文档来查找事件处理程序方法的外观。

public event EventHandler Clicked 公共事件EventHandler已点击

The event uses .NETs EventHandler so it will get an object sender and an EventArgs args as parameter. 该事件使用.NETs EventHandler,因此它将获得一个对象发送者和一个EventArgs args作为参数。

Xamarin Button Clicked EventHandler Xamarin按钮单击EventHandler

//You may have to change the Name depending on how you name that handler in xaml

void OnButtonClicked(object sender, EventArgs args)
{

}

Update: 更新:

Of course you have to add 当然要加

using System;

at the top of your file in order to use EventArgs. 在文件顶部以使用EventArgs。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM