Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

c# - 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.

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.

I am using Visual Studio Enterprise edition 2017.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Working with Intellisense

In VisualStudio ctrl+space to kick intellisense. Move your cursor right between the quotes, as seen in the image below, and hit ctrl+space. Intellisense should pop up now suggesting to create an event handler.

image of xaml-event

Manual Solution

In general you could use the Xamarin documentation to find out how the event handler method should look like.

public event EventHandler Clicked

The event uses .NETs EventHandler so it will get an object sender and an EventArgs args as parameter.

Xamarin Button Clicked 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...