Reputation: 11712
How to get the reference to the specific native view, not UIView? This is my custom Label renderer:
public class MyLabelRenderer : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
//how to get UILabel reference created by base LabelRender?
base.OnElementChanged(e);
}
}
I have used this Renderer Sample as an example.
Upvotes: 1
Views: 4673
Reputation: 7692
You need to use the Control property of the renderer. It theoretically should be available in the OnElementChanged method. But, on some platforms like UWP, the custom renderer just literally is the native control.
Upvotes: 0
Reputation: 16232
The reference you used is outdated. Use this one http://forums.xamarin.com/discussion/comment/59303
the native view can be accessed through the Control
property, provided that you called SetNativeControl()
:
protected override void OnElementChanged (ElementChangedEventArgs<MyCustomView> e)
{
base.OnElementChanged (e);
if (e.OldElement == null) {
// perform initial setup
SetNativeControl (new UIMyCustomView (RectangleF.Empty));
}
UpdateSomething ();
}
Upvotes: 1