PlotModel not available for several plot controls

Jul 12, 2012 at 10:17 AM
Edited Jul 12, 2012 at 10:20 AM


Firstly, congratulations and thank you for this super project. and thank you for sharing that !

I have a question about the Plot class in OxyPlot.WPF namespace.

Due to InvalidOperationException ("This PlotModel is already in use by some other plot control.") ,

,it is not possible for several plotControls to have the same PlotModel. Is there a reason to this choice ?

I thought that could be interesting to have the possibility to represent several plotControl to different location of an application, all bound on the same PlotModel.

In this case, the code in the OnModelChange() method would be :

 if (this.Model != null)
                    if (this.Model.PlotControl == null)                    
                        this.currentModel = this.Model;

What do you think about that ?

Thank you very much.

Jul 12, 2012 at 10:59 AM

The PlotModel is a "ViewModel" for the Plot - currently a lot of view-specific data is stored in there(e.g. axis scaling, coordinates transformed to screen space) , and it cannot be used in more than one view. I prefer to keep it this way (could of course also make the PlotModel contain only plot data, and a PlotViewModel containing the view specific data, but I think this would be more work...)

Jul 12, 2012 at 11:36 AM

Ok, I understand.

In this case, imagine the following scenario:

We have a UserControl hosting a PlotControl (with binding on a PlotModel), this UserControl DataContext is bound on a ViewModel called myVm (this ViewModel has so a PlotModel property)

For you, what would be the best way to reuse an other instance of this UserControl but bound on the same ViewModel instance (myVm) ?


Jul 13, 2012 at 7:40 AM

I would not reuse the same instance of the view model in different views. Can you create different instances?

Jul 13, 2012 at 8:50 AM

Indeed, even if my view model receive some modifications before display the new userControl, I think this is the most reasonable solution.

Thank you.

Jul 24, 2012 at 8:10 AM


I have a question that is directly related to this subject.
I have a viewmodel that contains an ObservableCollection of PlotModel. This collection is binded on the ItemsSource property of a ListView. For displayinf charts, I use a datatemplate. Here is my XAML :

 <ListView ItemsSource="{Binding PlotModels, Mode=OneWay}" ItemTemplate="{StaticResource ResourceKey=NamedCacheStatsTemplate}">
                    <WrapPanel Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" 
                                   ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}" 
                                   MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}" 
                                   ItemHeight="{Binding (ListView.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListView}}" />
<DataTemplate x:Key="NamedCacheStatsTemplate" DataType="{x:Type oxymodel:PlotModel}">
        <oxy:Plot Model="{Binding}" MinHeight="300" MinWidth="600"/>

My viewmodel retrieves statistics from a webservice every 5 seconds, updates the existing plotmodels in the observablecollection of plotmodel, and call RaisePropertyChanged("PlotModels") for updating the UI. When the UI is updated, the exception InvalidOperationException ("This PlotModel is already in use by some other plot control.") is thrown.

Is there something wrong in my usage of OxyPlot, or, is there a workaround for this problem ?
Thanks in advance for your reply,

Best regards.



Aug 8, 2012 at 10:29 PM

I need a small test application to reproduce this bug. Can create it myself (will take some time) or maybe you can help? cheers!

Nov 4, 2012 at 8:04 AM


Firs I go with Patoon congratulations and thank...

I have the same problem

I use ListView with GroupBy option (using CollectionViewSource)

When I change the GroupBy (setting the CollectionViewSource.GroupDescriptions), WPF try to create a new control while the old one is still exist !


Best regards.

Nov 4, 2012 at 9:22 PM

Thanks for the bug report! Need a small test application to reproduce this bug.

Nov 5, 2012 at 7:23 AM

I reproduce the bug, how can I send it to you ?

Nov 6, 2012 at 6:43 PM

I suggest for single code files, or create a fork with the new example in Source\Examples\WPF

Is this the same bug as in

Otherwise we should create a new issue.

Nov 27, 2012 at 2:27 PM

@isaacd1: Can you send your results, for analysing the problem? Thanks

Nov 30, 2012 at 8:32 AM


It seems that only reloading the chart control causes this error. For instance, I use the Avalon Docking framework and whenever I switch from one tab to the other or float/dock a panel, I get this error. Is there any way to disable this check in the code? 

Thank you.

Dec 3, 2012 at 6:38 AM

Please test the latest version. I checked in a change Nov 23 related to loading/unloading the WPF control, I think this is the same problem as you encountered. I have tested the latest version with AvalonDock without problems.

Mar 12, 2013 at 10:56 PM

I'm getting the same error, but under rather strange conditions.

I have a class that holds certain data, among which is a PlotModel for an OxyPlot. I display objects of this class in a DataGrid, an excerpt of the code:
                                    <DataGridTextColumn Header="#" Width="Auto"/>
                                    <DataGridTemplateColumn Header="Image" Width="*">
                                                <Image Source="{Binding Path=DisplayImage}"></Image>

                                    <DataGridTemplateColumn Header="Chart" Width="*">
                                                <oxy:Plot Model="{Binding PM}" MinHeight="150">
When using the application, the user select certain parts of an image, those parts are analyzed and the data is displayed on a plot. The user is expected to select many regions of interest, so we get many plots, all listed neatly in a DataGrid.

Here's the interesting part. The problem only occurs if you scroll around, and only after a certain amount of time.

What's more is that it never occurs if the DataGrid is placed inside a ScrollViewer. So the workaround is obvious, I could just use ScrollViewer and be done with it, but it gives me other pains because the header is scrolled along with everything else. Any idea how to fix this?
Mar 20, 2013 at 1:45 PM
Edited Mar 20, 2013 at 2:59 PM
I hate to bump this, but this issue is really giving me some serious problems.

Anyone, please?

EDIT: obviously the problem is virtualization, if I turn it off for the DataGrid, the exception doesn't occur anymore. So reloading the control is still an issue?
Apr 10, 2013 at 9:56 AM
Edited Apr 10, 2013 at 9:56 AM
objo wrote:
I would not reuse the same instance of the view model in different views. Can you create different instances?
Hi. I'm trying this too, but even after I create an instance of my PlotModel, when I use this new instance with another plot, I get the same error.
Sep 1, 2014 at 12:11 PM
In the new version, I have this popping up on the designer.

Use case:

Main window has tab control. Tab control has a VM with a chart.
Opening both MainWindow.xaml and TabControl.xaml will show the chart in one, but will show the exception in the other.
Sep 1, 2014 at 6:11 PM
I added the following issue:
Note that this forum is no more in use, this thread has been moved to