Skip to content

Commit 100346d

Browse files
committed
try to fix an exception on Mac
* InvalidOperationException: This PlotModel is already in use by some other PlotView control * on Mac we introduce the method PlotViewRenderer.DetachModelFromView (analogous to Android)
1 parent 75762d6 commit 100346d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Source/OxyPlot.Xamarin.Forms.Platform.MacOS/PlotViewRenderer.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.P
5252
return;
5353
}
5454

55+
this.DetachModelFromView();
56+
5557
var plotView = new PlotView
5658
{
5759
Model = this.Element.Model,
@@ -78,6 +80,7 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
7880

7981
if (e.PropertyName == Xamarin.Forms.PlotView.ModelProperty.PropertyName)
8082
{
83+
this.DetachModelFromView();
8184
this.Control.Model = this.Element.Model;
8285
}
8386

@@ -95,5 +98,14 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
9598
this.Control.InvalidatePlot (false);
9699
}
97100
}
101+
102+
void DetachModelFromView()
103+
{
104+
var model = base.Element.Model as OxyPlot.IPlotModel;
105+
if (model != null)
106+
{
107+
model.AttachPlotView(null);
108+
}
109+
}
98110
}
99111
}

0 commit comments

Comments
 (0)