0

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.

Tobias Theel
  • 3,088
  • 2
  • 25
  • 45
Amit Bhagat
  • 71
  • 1
  • 2
  • 4
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Jan 07 '18 at 13:37
  • Do you have any errors, when you try to build/run your project? A non working intellisense is sometimes a symptom that something is broken in your project. – Tobias Theel Jan 07 '18 at 13:42

1 Answers1

8

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.

Tobias Theel
  • 3,088
  • 2
  • 25
  • 45
  • Thanks.. I tried this but when I add EventArgs it is not shown as recognized class(usually shown in blue color). So am not able to do it. – Amit Bhagat Jan 07 '18 at 13:31
  • I updated the answer. You have to add the using for system in order to use EventArgs. If that does not help, please descripe your problem in more detail, as this has to work, as this is the correct way how to implement a clickHandler. I have also tested it - which proves me that works – Tobias Theel Jan 07 '18 at 13:38
  • using System is already added at the top, but still the EventArgs class is not available. I suppose there is some bug in Visual Studio 2017 – Amit Bhagat Jan 08 '18 at 04:33
  • 1
    Thanks..I got it resolved...There was some issue with the project dependencies hence the Eventargs class was not visible. I created new project and tried manual solution, now it is working fine for button click events. – Amit Bhagat Jan 08 '18 at 06:20
  • How do you add event handler C# in code? In JavaScript you write button.addEventListener("click", buttonHandler); I can find nothing for C# – 1.21 gigawatts May 24 '21 at 12:20