简体   繁体   English

关闭没有项源的Tabcontrol的虚拟化-WPF

[英]Turning off Virtualization for Tabcontrol without itemsource - WPF

I have a bug with Tabcontrols and Oxyplot. 我在Tabcontrols和Oxyplot中有一个错误。 The Structure of my xaml is like this: I have an AvalonDock document and inside I have 3 harcoded tabs for each document. 我的xaml的结构是这样的:我有一个AvalonDock文档,并且在内部每个文档有3个编码标签。 One of those tabs has another tabcontrol with an Oxyplot View inside each tab. 这些选项卡中的一个选项卡具有另一个选项卡控件,每个选项卡内均具有Oxyplot视图。 Problem is when I open two (sometimes three) Avalondock Documents, I get the following exception: 问题是当我打开两个(有时是三个)Avalondock文档时,出现以下异常:

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. 我猜这是因为tabcontrol正在虚拟化选项卡,并且图模型多次用于不同的视图。 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/ 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 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. 索尔·伊达尔戈(Saul Hidalgo)。

You can use the following code to remove view from PlotModel 您可以使用以下代码从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);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM