首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SciChart (C# WPF)。TextAnnotation中绑定文本属性的问题

SciChart (C# WPF)。TextAnnotation中绑定文本属性的问题
EN

Stack Overflow用户
提问于 2020-08-26 06:46:52
回答 1查看 216关注 0票数 1

我有一个简单的SciChart CompositeAnnotation:

代码语言:javascript
复制
 <s:CompositeAnnotation x:Class="KernelDensity.DensityAnnotation"
         xmlns:s="http://schemas.abtsoftware.co.uk/scichart"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         Canvas.ZIndex="1" MouseDoubleClick="DensityAnnotation_OnMouseDoubleClick">
<s:CompositeAnnotation.Annotations>
    <s:BoxAnnotation x:Name="DensityBoxArea" Background="#FFBADAFF" BorderBrush ="Black" BorderThickness="1" CoordinateMode="Relative" CornerRadius="1" Width="1" Height="1" Opacity="0.5" X1="0" X2="1" Y1="0" Y2="1" >
        <s:BoxAnnotation.Template>
            <ControlTemplate TargetType="s:BoxAnnotation">
                <Border x:Name="PART_BoxAnnotationRoot"
                        Margin="{TemplateBinding Margin}"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        CornerRadius="{TemplateBinding CornerRadius}">
                    <Image x:Name="DensityPlot" Width="Auto" Stretch="Fill"/>
                </Border>
            </ControlTemplate>
        </s:BoxAnnotation.Template>
    </s:BoxAnnotation>
    <s:TextAnnotation x:Name="SelectedSeriesTextAnnotation"
                      Background="Black"
                      CoordinateMode="Relative"
                      CornerRadius="3"
                      Foreground="White"
                      HorizontalAnchorPoint="Center"
                      X1="0.5"
                      Y1="0.5"
                      FontSize="14"
                      Text="{Binding SelectedSeriesTextAnnotationText}">
    </s:TextAnnotation>
</s:CompositeAnnotation.Annotations>
<s:CompositeAnnotation.ToolTip >
    <ToolTip Placement="Right">
        <TextBlock Text="{Binding SelectedSeriesTextAnnotationText}" FontSize="15" Foreground="Black"/>
    </ToolTip>
</s:CompositeAnnotation.ToolTip>
</s:CompositeAnnotation>

在这里,您可以看到TextAnnotation属性和TextBlock Text属性具有相同的绑定到我的视图模型属性。问题是,这种绑定对于ToolTip TextBlock文本属性是正确的,但是对于TextAnnotation文本属性则不起作用(就好像根本没有绑定一样)。我怎样才能解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-27 16:38:53

在诊断任何绑定问题时,首先要检查的是Visual输出窗口中是否有任何警告。在控制台/输出窗口中查找这样的行

System.Windows.Data信息: 10 :无法使用绑定检索值,并且不存在有效的回退值;使用默认值代替。BindingExpression:Path=IDontExist;DataItem=null;目标元素是‘TextBlock’(Name=);目标属性是‘Text’(输入‘String’)

如果输出窗口中没有BindingExpression错误,接下来要检查的是未能绑定的对象的DataContext。这是什么类型的?是在运行时设置的吗?

检查绑定的一个很好的工具是WPF Snoop。您可以悬停一个项目,并看到属性活动。您还可以在那里看到绑定错误。有一个相关的问题和答案,它展示了如何做到这一点。

如果存在绑定错误,则会显示为红色,您可以在运行时检查DataContext是否为null或错误类型。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63591965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档