[forms-devel] Fixing SetNativeControl logic when replacing native controls

Toni Petrina tonipetrina at hotmail.com
Sat Jul 2 16:22:42 UTC 2016


Hi,

 

It is hard to replace a native control inside a renderer with your own. You cannot even replace ListView in Android because there are nasty NullRefs happening if you do so! Consider the following code:

 

var ctx = Context;
nativeListView = new AListView(ctx);
_refresh = new SwipeRefreshLayout(ctx);
_refresh.SetOnRefreshListener(this);
_refresh.AddView(nativeListView, LayoutParams.MatchParent);
SetNativeControl(nativeListView, _refresh); 

 

 

If I want to use my subclass instead of Android.Widget.ListView, I have to reimplement entire ListViewRenderer which is impossible due to all internal classes. It would be much better if there is a method called GetNativeControll so that the above code looks more like:

 

protected override AListView GetNativeControl() => new AListView(Context); 

 ()) 

var ctx = Context;
nativeListView = GetNativeControl();


This way I can override the default control to be used with my own subclass.

 

Cheers

Toni Petrina

 

P.S. Not having markdown in email is frustrating!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/forms-devel/attachments/20160702/56bc23b6/attachment.html>


More information about the forms-devel mailing list