0

OxyPlot Bar Chart inside a listview control for Xamarin.Forms

Naveen Gogineni 1 year ago in Bugs • updated 1 year ago 0

I have a ListView with a binding template. And I have a list of PlotModels which I am using to bind to the list view.
And my PlotView is inside the template where I am binding the PlotModel to the PlotView.

Everything is running smooth in Android. But the problem is I am getting a error "PlotModel is already in use by some other PlotView control.".
when I am trying to run it on IOS.


//My content page
public MyConstructor()
{
List<MyChart> charts = new List<MyChart>();
charts.Add(new MyChart { PlotModel = PlotModel1 });
charts.Add(new MyChart { PlotModel = PlotModel2 });
charts.Add(new MyChart { PlotModel = PlotModel3 });
charts.Add(new MyChart { PlotModel = PlotModel4 });
ListView lvPlots = new ListView(ListViewCachingStrategy.RetainElement)
{
ItemsSource = charts,
ItemTemplate = new DataTemplate(typeof(NewDashboardSubCell)),
HasUnevenRows = true
};
Content = lvPlots;
}

public class MyChart
{
       public MyPlotModel PlotModel { get; set; }
}

//My View Cell
public class NewDashboardSubCell : ViewCell
{
        PlotView plotView;
        public NewDashboardSubCell()
        {
            try
            {
                plotView = new PlotView
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions = LayoutOptions.FillAndExpand,
                    IsVisible = true,
                    IsEnabled = true,
                    HeightRequest = App.ScreenHeight - 100,
                    WidthRequest = App.ScreenWidth - 40
                };

                plotView.SetBinding(PlotView.ModelProperty, "PlotModel");

                View = plotView;                
            }
            catch (Exception ex)
            {
            }
        }
}