我正在尝试解决性能问题。当前的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>
还有另一个我不知道的后备功能,可以使我处理工具提示生成的异常。
注意:该信息仍在屏幕上正确显示。仅在创建时(当我更改模型以更改视图以创建具有此工具提示的元素时),才会出现这些错误。
答案 0 :(得分:1)
您可以使用DataTrigger
处理此事件。请注意,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>