2016-09-08 4 views
0

Ich habe den folgenden Code benutzerdefinierten iOS UIButton in Xamarin zu erstellen:UIButton mit Typ-Gewohnheit verliert Ereignis Klicken

protected override void OnElementChanged(ElementChangedEventArgs<Button> e) 
    { 
     // will have to create a native Custom type of ios button to avoid text dimming 
     // when touched 

     // logic of element processing from 
     // https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/view/ 

     // except we don't call the base immediately 
     // because it will create the Control for us, but we don't want that here 
     if (Control == null) 
     { 
      // instantiate the native control and assign it to the Control property with 
      // the SetNativeControl method 
      uiBtn = new UIButton(UIButtonType.Custom); 
      SetNativeControl(uiBtn); // should set Control to the newly created element 
      // and prevent base.OnElementChanged(e) from creating a new element instead 
     } 

     base.OnElementChanged(e); 

     // some button customization code here - it does not matter, the issue happens also without it... 

Der Code Renderer funktioniert gut, aber jetzt kann ich keine Clicked Ereignisse auf meinem Xamarin.Forms erhalten Taste.

Wie stelle ich die Funktion "Verlorener Klick" wieder her?

Antwort

1

schließlich in Xamarin Quellcode fand ich dies:

https://github.com/xamarin/Xamarin.Forms/blob/2d9288eee6e6f197364a64308183725e7bd561f9/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs

und Blick auf OnElementChanged Ich war etwas überrascht, dass Ereignisse nur angebracht werden, wenn diese Instanz von OnElementChanged schafft eigentliches Element. Nicht sicher, warum es so gemacht wird, aber zumindest jetzt weiß ich, dass wenn ich selbst eine Kontrolle erstelle, dann muss ich auch das Klick-Ereignis selbst verkabeln.