Turning off Virtualization for Tabcontrol without itemsource - WPF

社会主义新天地 提交于 2020-01-14 04:45:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!