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

Cannot dispose of custom renderer

$
0
0

Hi,

I wrote a contenview renderer based on the roundedbowview code. It works except when I try to navigate to another page. Then I have the below error:

at Xamarin.Forms.Platform.iOS.ViewRenderer2[BattleQuiz.Controls.RoundedContentView,MonoTouch.UIKit.UIView].Dispose (Boolean disposing) [0x00000] in <filename unknown>:0 \n at MonoTouch.Foundation.NSObject.Dispose () [0x00000] in /Developer/MonoTouch/Source/maccore/src/Foundation/NSObject2.cs:127 \n at Xamarin.Forms.Platform.iOS.Platform.DisposeModelAndChildrenRenderers (Xamarin.Forms.Element view) [0x00000] in <filename unknown>:0 \n at Xamarin.Forms.Platform.iOS.Platform.HandleChildRemoved (System.Object sender, Xamarin.Forms.ElementEventArgs e) [0x00000] in <filename unknown>:0 \n at Xamarin.Forms.Element.OnDescendantRemoved (Xamarin.Forms.Element child) [0x00000] in <filename unknown>:0 \n at Xamarin.Forms.Element.OnChildRemoved (Xamarin.Forms.Element child) [0x00000] in <filename unknown>:0 \n at Xamarin.Forms.Page.OnInternalRemoved (Xamarin.Forms.VisualElement view) [0x00000] in <filename unknown>:0 \n at Xamarin.Forms.Page.InternalChildrenOnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in <filename unknown>:0 \n at System.Collections.ObjectModel.ObservableCollection1[Xamarin.Forms.Element].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00014] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.15/src/mono/mcs/class/System/System.Collections.ObjectModel/ObservableCollection.cs:161 \n at System.Collections.ObjectModel.ObservableCollection1[Xamarin.Forms.Element].RemoveItem (Int32 index) [0x0001a] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.15/src/mono/mcs/class/System/System.Collections.ObjectModel/ObservableCollection.cs:182 \n at System.Collections.ObjectModel.Collection1[Xamarin.Forms.Element].Remove (Xamarin.Forms.Element item) [0x00011] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs:134 \n at Xamarin.Forms.MasterDetailPage.set_Detail (Xamarin.Forms.Page value) [0x00000] in :0 \n at ...

Here is the renderer

class RoundedContentViewRenderer : ViewRenderer<RoundedContentView, UIView>
    {

        protected override void OnElementChanged(ElementChangedEventArgs<RoundedContentView> e)
        {
            base.OnElementChanged(e);

            var rcv = e.NewElement;
            if (rcv != null)
            {

                NativeView.Layer.CornerRadius = (float)rcv.CornerRadius;
                NativeView.Layer.BorderColor = rcv.Stroke.ToCGColor();
                NativeView.Layer.BorderWidth = (float)rcv.StrokeThickness;
                NativeView.Layer.MasksToBounds = true;
                NativeView.Layer.BackgroundColor = rcv.BackgroundColor.ToCGColor();
                NativeView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            }
        }

        protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName == RoundedContentView.CornerRadiusProperty.PropertyName)
                NativeView.Layer.CornerRadius = (float)this.Element.CornerRadius;
            else if (e.PropertyName == RoundedContentView.StrokeProperty.PropertyName)
                NativeView.Layer.BorderColor = this.Element.Stroke.ToCGColor();
            else if (e.PropertyName == RoundedContentView.StrokeThicknessProperty.PropertyName)
                NativeView.Layer.BorderWidth = (float)this.Element.StrokeThickness;
            else if (e.PropertyName == RoundedContentView.BackgroundColorProperty.PropertyName)
                NativeView.Layer.BackgroundColor = this.Element.BackgroundColor.ToCGColor();
}
}

On a side note I'm surprised that I had to change the layer background based on contentview background. Why wasn't the layer background color already equal to the contentview one?


Viewing all articles
Browse latest Browse all 58056

Trending Articles