问题
I have a bug with Tabcontrols and Oxyplot. The Structure of my xaml is like this: I have an AvalonDock document and inside I have 3 harcoded tabs for each document. One of those tabs has another tabcontrol with an Oxyplot View inside each tab. Problem is when I open two (sometimes three) Avalondock Documents, I get the following exception:
This PlotModel is already in use by some other PlotView control.
I guess it is because the tabcontrol is virtualizing the tabs, and the plot model is being used several times for different views. How can I prevent it?
Problem is very similar to this one,
http://discussion.oxyplot.org/topic/506228-error-this-plotmodel-is-already-in-use-by-some-other-plotview-control/
but I don't think it doesn't have solution yet. I tried the virtualization-off solution given here
http://www.codeproject.com/Articles/460989/WPF-TabControl-Turning-Off-Tab-Virtualization
and worked properly, but that was for tabs from a template and Not from hardcoded tabs.
Any ideas?
Thanks
Regards.
Saul Hidalgo.
回答1:
You can use the following code to remove view from PlotModel
private PlotVm vm = new PlotVm();
private void LayoutRoot_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
var window = new PlotWindow();
((IPlotModel)vm.Model)?.AttachPlotView(null);
window.DataContext = vm;
Debug.WriteLine(vm.Model.PlotView);
window.ShowDialog();
Debug.WriteLine(vm.Model.PlotView);
}
来源:https://stackoverflow.com/questions/27519776/turning-off-virtualization-for-tabcontrol-without-itemsource-wpf