简体   繁体   English

使用 TabControl 时 SciChart CompositeAnnotation 消失

[英]SciChart CompositeAnnotation disappearing when using TabControl

I have created a composite annotation (named PeakAnnotation) that consists of four elements: two VerticalLineAnnotations, a BoxAnnotation, and a TextAnnotation.我创建了一个复合注释(名为 PeakAnnotation),它由四个元素组成:两个 VerticalLineAnnotation、一个 BoxAnnotation 和一个 TextAnnotation。 When I first add the annotation, everything appears correctly.当我第一次添加注释时,一切都正确显示。 However, when I change between tabs in my TabControl... the BoxAnnotation disappears .但是,当我在 TabControl 中的选项卡之间切换时…… BoxAnnotation 消失了 The box will reappear when I move the composite annotation a few pixels by dragging it with the cursor.当我使用 cursor 拖动复合注释几个像素时,该框将重新出现。

I have tried calling ZoomExtents() and InvalidateElement() , but does not fix the issue.我试过调用ZoomExtents()InvalidateElement() ,但没有解决问题。

I've created a simple app to reproduce the issue in a simple minimal way.我创建了一个简单的应用程序,以一种简单的最小方式重现该问题。

PeakAnnotation.xaml PeakAnnotation.xaml

<s:CompositeAnnotation x:Class="WpfPresentation.Views.PeakAnnotation"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:s="http://schemas.abtsoftware.co.uk/scichart"
                Canvas.ZIndex="1" 
                DragDirections="XDirection"
                ResizeDirections="XDirection"
                IsEditable="True">

<s:CompositeAnnotation.Annotations>
    <s:VerticalLineAnnotation CoordinateMode="Relative" Stroke="#FFBADAFF" StrokeThickness="2" X1="0" X2="0" Y1="0" Y2="1"/>
    <s:VerticalLineAnnotation CoordinateMode="Relative" Stroke="#FFBADAFF" StrokeThickness="2" X1="1" X2="1" Y1="0" Y2="1"/>
    <s:BoxAnnotation x:Name="box" Opacity="0.2" CornerRadius="2" Background="#FFBADAFF" BorderBrush="#1964FF" CoordinateMode="Relative" X1="0" X2="1" Y1="0" Y2="1"/>
    <s:TextAnnotation x:Name="AnnotationTextLabel" CoordinateMode="Relative" X1="0" Y1="0.95" FontSize="12" Foreground="White"/>
</s:CompositeAnnotation.Annotations>

</s:CompositeAnnotation>

PeakAnnotation.xaml.cs PeakAnnotation.xaml.cs

public partial class PeakAnnotation : CompositeAnnotation
{
    public PeakAnnotation()
    {

    }
    
    public PeakAnnotation(string annotationText)
    {
        InitializeComponent();
        AnnotationTextLabel.Text = annotationText;
    }

    public string StyleKey { get; set; }

    public Type ViewType => throw new NotImplementedException();
}

MainViewModel.cs主视图模型.cs

public MainViewModel()
    {
        ChartTitle = "Testing";

        Annotations = new AnnotationCollection();

        var myAnnotation = new PeakAnnotation("My Annotation Title")
        {
            X1 = 40,
            X2 = 50,
            Y1 = 0,
            Y2 = 100
        };

        Annotations.Add(myAnnotation);
    }
    public string ChartTitle { get; set; }
    public AnnotationCollection Annotations { get; set; }
}

MainWindow.xaml主窗口.xaml

<Window x:Class="SciChartTesting.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:SciChartTesting" xmlns:s="http://schemas.abtsoftware.co.uk/scichart"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">

<Window.Resources>
    <local:MainViewModel x:Key="MainViewModel"/>
</Window.Resources>

<Grid DataContext="{StaticResource MainViewModel}">
    <TabControl>
        <TabItem Header="TabOne">
            <Label Content="This is TabOne"/>
        </TabItem>
        <TabItem Header="TabTwo">
            <s:SciChartSurface ChartTitle="{Binding ChartTitle}" Annotations="{Binding Annotations}">
                <s:SciChartSurface.XAxis>
                    <s:NumericAxis VisibleRange="0,100"/>
                </s:SciChartSurface.XAxis>
                <s:SciChartSurface.YAxis>
                    <s:NumericAxis VisibleRange="0,100"/>
                </s:SciChartSurface.YAxis>
            </s:SciChartSurface>
        </TabItem>
    </TabControl>
</Grid>

Working annotation:工作注释: 工作示例

Broken annotation:损坏的注释: 在此处输入图像描述

The TabControl only uses a single shared ContentPresenter to display the contents of a TabItem . TabControl仅使用单个共享ContentPresenter来显示TabItem的内容。 This means it completely removes the content from the visual tree between tab navigation.这意味着它完全从选项卡导航之间的可视树中删除了内容。 Rendering details like adorner layers or state of triggers are not preserved.不保留触发器的装饰层或 state 等渲染细节。 You have to explicitly redraw the annotation element on content load eg using a trigger.您必须在内容加载时显式重绘注释元素,例如使用触发器。

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

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