Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Right pattern to intercomunicate Forms with native controls

$
0
0

Hi.

I'm creating an app with the Forms framework and I'm really liking it.

I have created custom renderers, custom controls, etc etc and I have now a doubt, which is the right pattern to intercomunicate the Forms element with the native control?

Let me explain with a sample. Lets supose we are creating a "HappyControl", on the Forms side we have:

public class HappyControl : View {  /*....*/   }

And on the native side we have:

public class HappyControlRenderer: ViewRenderer<HappyControl, NativeHappyControl>{ /*...*/ }
public class NativeHappyControl : RelativeLayout { /*...*/ }

So, if the NativeHappyControl now exposes some functions:

public class NativeHappyControl : RelativeLayout {

    public void ShowHappynes(){ /**/ }
    public void ShowSadness() { /**/ }
}

Where is the right place to call these funcions an make them available to the Forms element?

Of course an Event/Funcion call system can be used (Element exposes event, Custom renderer hooks to them, when Element fires events the renderer receives the call and executes the function) but I belive there must be a better way of doing this, it seems a bit dirty to me.

Is there a better approach to this?

Cheers.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>