0

我正在尝试解决性能问题。当前的 gremlin 是我的工具提示,它抛出:

System.Windows.Data Information: 41 : BindingExpression path error: 'ViewLine3' property not found for 'object' because data item is null.  This could happen because the data provider has not produced any data yet. BindingExpression:Path=ViewLine3; DataItem=null; target element is 'TextBlock' (Name='line3ToolTip'); target property is 'Text' (type 'String')
System.Windows.Data Information: 20 : BindingExpression cannot retrieve value due to missing information. BindingExpression:Path=ViewLine3; DataItem=null; target element is 'TextBlock' (Name='line3ToolTip'); target property is 'Text' (type 'String')
System.Windows.Data Information: 21 : BindingExpression cannot retrieve value from null data item. This could happen when binding is detached or when binding to a Nullable type that has no value. BindingExpression:Path=ViewLine3; DataItem=null; target element is 'TextBlock' (Name='line3ToolTip'); target property is 'Text' (type 'String')

对于实现它的每个项目。我试图通过设置 FallbackValue、TargetNullValue、Delay、IsAsync 来使其静音,但问题仍然存在。

<StackPanel.ToolTip>
    <ToolTip>

        <StackPanel x:Name="suiteTooltip" 
                    Width="auto">
            <TextBlock  x:Name="line3ToolTip" 
                        Text="{Binding ViewLine3, 
                        FallbackValue='NoData', 
                        TargetNullValue='NoData', 
                        Delay=500, 
                        IsAsync=True}"/>
        </StackPanel>
    </ToolTip>
</StackPanel.ToolTip>

是否有另一个我不知道的后备方法可以让我处理工具提示生成的异常。

注意:信息仍在屏幕上正确显示。只有在创建时(当我更改模型以更改视图以创建具有此工具提示的元素时)才会出现这些错误。

4

1 回答 1

1

您可以使用 aDataTrigger来处理此事件。请注意,FallBackValue当绑定失败时使用它,在您的情况下它不会(它找到属性),这就是您看到它不起作用的原因。

<TextBlock>
  <TextBlock.Style>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="Text" Value="{Binding ViewLine3, FallbackValue='NoData', TargetNullValue='NoData', 
                    Delay=500, IsAsync=True}"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding ViewLine3}" Value="{x:Null}">
                    <Setter Property="Text" Value="NoData"/>
                </DataTrigger>
                  <DataTrigger Binding="{Binding Path=ViewLine3.Length, FallbackValue=0, TargetNullValue=0}" Value="0">
                    <Setter Property="Text" Value="NoData"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
</TextBlock>
于 2019-10-25T15:40:25.463 回答