-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bar chart inside a ListView control #60
Comments
This is a very common issue of OxyPlot when it's used in MVVM. A quick fix is to break the MVVM design here a little bit. Don't create the model in a separated place but create the model in the view. So whenever a view is re-created by iOS or Android, a new model is also re-created. You can see issue #17 as well. |
iOS had a recent regression where ListViews on iOS were instantiating views for listview elements too much, this may help you: https://bugzilla.xamarin.com/show_bug.cgi?id=56896 Note that the ListView implementation may still instantiate a view multiple times if it needs to estimate the height. But once the issue is fixed (or if you use an earlier version of forms) you should be able to suppress these extra view creations by setting RowHeight on the ListView. See the PR in the bugzilla issue for notes about how that works. |
FWIW now I'm butting into the same issue when using OxyPlot in a carouselview (https://github.com/alexrainman/CarouselView). |
As @flyingxu said, you need to create a new PlotModel every time a new PlotView is used. Easiest way to achieve that is to construct the PlotModel within the same constructor as your PlotView. When using this within a CarouselView, ensure that you use a DataTemplate and not a direct reference to the View. The DataTemplate should be constructed to ensure that a new version is created every time (i.e. on swipe and rotate) var myCarousel = new CarouselViewControl();
myCarousel.ItemsSource = new List<DataTemplate>()
{
new DataTemplate(() => { return pairList; } ), //this view can be cached/re-used
new DataTemplate(() => { return singlePair; }), //this view can be cached/re-used
new DataTemplate(() => {
tickChart = new Views.TickChart(); //need a new one every time!
return tickChart;
})
};
myCarousel.PositionSelected += OnPositionSelected;
Content = myCarousel; |
Steps to reproduce
Platform: Xamarin Forms (Cross-Platform)
.NET version: 4.0
Expected behaviour
While loading the ContentPage, the ListView should load the data based on the PlotModels provided.
Actual behaviour
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 IPhone.
Code.txt
The text was updated successfully, but these errors were encountered: