Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How Can I Create an Event in a Custom Renderer and Call the Event From Xam Forms Page Code Behind

RobertTRobertT USMember ✭✭

I feel sure I need to create an Event Delegate in my Forms ControlView.cs. But I can't quite figure out the syntax to expose the event from the ControlViewRederer.cs in my Android project. Anybody have a simple example of this?

Best Answers

  • RobertTRobertT USMember ✭✭
    Accepted Answer

    OK, Got it. One change I had to make to your code LandLu.

    Your code in Xam Forms project
    public delegate void DoSomeDelegate(string parameter, Action callback);
    public DoSomeDelegate OnDoing;

    Changed to
    public delegate void DoSomeDelegate(string parameter, Action callback);
    public event DoSomeDelegate OnDoing;

    This change allowed me to assign the event handler in the renderer.

    Thanks again.

Answers

  • RobertTRobertT USMember ✭✭

    Thank you LandLu for that example. I almost had that. :)

    That is just what I am looking for. However I am rendering a Xamarin.Forms.View object. The Xamarin.Forms.View doesn't have an OnDoing method. I'll look for another method in the Xamarin.Forms.View that I can use to assign the Event to.... If you know it off hand that would be great!

  • RobertTRobertT USMember ✭✭

    Opps. Think I get it now. Will let you know if solves.

  • RobertTRobertT USMember ✭✭
    Accepted Answer

    OK, Got it. One change I had to make to your code LandLu.

    Your code in Xam Forms project
    public delegate void DoSomeDelegate(string parameter, Action callback);
    public DoSomeDelegate OnDoing;

    Changed to
    public delegate void DoSomeDelegate(string parameter, Action callback);
    public event DoSomeDelegate OnDoing;

    This change allowed me to assign the event handler in the renderer.

    Thanks again.

  • rupeshcommrupeshcomm Member ✭✭
    edited May 4

    How to send back the value from AVCaptureMetadataOutputObjectsDelegate to the cs page

Sign In or Register to comment.