[英]Is there a Fallback for Dataitem=null
我正在嘗試解決性能問題。 當前的 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>
是否有另一個我不知道的后備方法可以讓我處理工具提示生成的異常。
注意:信息仍在屏幕上正確顯示。 只有在創建時(當我更改 model 以更改視圖以創建具有此工具提示的元素時)才會出現這些錯誤。
您可以使用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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.