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

Custom Controls, SetNativeControl and proper event handling

$
0
0

I am trying to use the Xlabs ImageGallery. In looking into the code it seems to have some issues with event handlers and I am just trying to get an understanding as to how it theoretically should be handled. If I create a page with the ImageGallery on it and I move to and from that page, the events will fire, once for each time the page has been displayed. This would indicate that the events are being assigned but not unassigned. Also there is a call to AddObserver in the Draw event (which also accumulates) but there is never a call to RemoveObserver. This is a more complicated control and it seems to use SetNativeControl to add a UIView to a Xamarin page.

I don't want to know specifically how to fix this one control. I am trying to get an understanding of best practice here for controls in general. What is correct handling for the events? The events can be assigned with += in the constructor. However, where should the -= be set? There is a Dispose method in the ImageGallery but it doesn't get called. If I had a UIViewController I could use the OnViewAppear and OnViewDisappear. What would the equivalent pair of methods be for a custom control?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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