Amit Bhagat
Amit Bhagat

Reputation: 81

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.

Upvotes: 0

Views: 19675

Answers (1)

Tobias Theel
Tobias Theel

Reputation: 3217

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.

Upvotes: 8

Related Questions