本文介绍了此XAML代码中的IsEmpty参考/成员在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解 IsEmpty 在此代码段中的来源( Path = Text.IsEmpty )(关于水印文本框):

I cannot understand where the IsEmpty comes from in this snippet of code (Path=Text.IsEmpty) (about a watermark TextBox):

<Grid Grid.Row="0" Background="{StaticResource brushWatermarkBackground}"
                   Style="{StaticResource EntryFieldStyle}" >
    <TextBlock Margin="5,2" Text="Type to search ..." Foreground="Gray"
               Visibility="{Binding ElementName=entry, Path=Text.IsEmpty,
                          Converter={StaticResource BooleanToVisibilityConverter}}"/>
    <TextBox Name="entry" Background="Transparent"/>
</Grid>

您可以看到字符串没有任何 IsEmpty 属性。 DependencyProperty 也没有任何 IsEmpty 成员。我什至尝试在对象浏览器窗口中搜索 IsEmpty ,但是没有任何相关结果解释该代码。

You can see a string does not have any IsEmpty property. A DependencyProperty also does not have any IsEmpty member. I've even tried searching the IsEmpty in the Object Browser window but there was not any relevant result explaining the code.

您能否在这里向我解释 IsEmpty 参考? (有关它的任何参考链接都很棒)。

Could you explain to me the IsEmpty reference here? (Any reference link about it is great).

推荐答案

IsEmpty 是正在从 CollectionView.IsEmpty

如何?

我对绑定应用了高跟踪

Visibility="{Binding ElementName=entry,
                     PresentationTraceSources.TraceLevel=High,
                     Path=Text.IsEmpty,
                     Converter={StaticResource BooleanToVisibilityConverter}}"

这是结果

System.Windows.Data Warning: 56 : Created BindingExpression (hash=40147308) for Binding (hash=39658150)
System.Windows.Data Warning: 58 :   Path: 'Text.IsEmpty'
System.Windows.Data Warning: 60 : BindingExpression (hash=40147308): Default mode resolved to OneWay
System.Windows.Data Warning: 61 : BindingExpression (hash=40147308): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 62 : BindingExpression (hash=40147308): Attach to System.Windows.Controls.TextBlock.Visibility (hash=2939094)
System.Windows.Data Warning: 67 : BindingExpression (hash=40147308): Resolving source
System.Windows.Data Warning: 70 : BindingExpression (hash=40147308): Found data context element: <null> (OK)
System.Windows.Data Warning: 74 :     Lookup name entry:  queried TextBlock (hash=2939094)
System.Windows.Data Warning: 65 : BindingExpression (hash=40147308): Resolve source deferred
System.Windows.Data Warning: 67 : BindingExpression (hash=40147308): Resolving source
System.Windows.Data Warning: 70 : BindingExpression (hash=40147308): Found data context element: <null> (OK)
System.Windows.Data Warning: 74 :     Lookup name entry:  queried TextBlock (hash=2939094)
System.Windows.Data Warning: 78 : BindingExpression (hash=40147308): Activate with root item TextBox (hash=46768536)
System.Windows.Data Warning: 108 : BindingExpression (hash=40147308):   At level 0 - for TextBox.Text found accessor DependencyProperty(Text)
System.Windows.Data Warning: 104 : BindingExpression (hash=40147308): Replace item at level 0 with TextBox (hash=46768536), using accessor DependencyProperty(Text)
System.Windows.Data Warning: 101 : BindingExpression (hash=40147308): GetValue at level 0 from TextBox (hash=46768536) using DependencyProperty(Text): ''
System.Windows.Data Warning: 108 : BindingExpression (hash=40147308):   At level 1 - for String.IsEmpty found accessor <null>
System.Windows.Data Warning: 108 : BindingExpression (hash=40147308):   At level 1 - for EnumerableCollectionView.IsEmpty found accessor RuntimePropertyInfo(IsEmpty)
System.Windows.Data Warning: 104 : BindingExpression (hash=40147308): Replace item at level 1 with EnumerableCollectionView (hash=40847598), using accessor RuntimePropertyInfo(IsEmpty)
System.Windows.Data Warning: 101 : BindingExpression (hash=40147308): GetValue at level 1 from EnumerableCollectionView (hash=40847598) using RuntimePropertyInfo(IsEmpty): 'True'
System.Windows.Data Warning: 80 : BindingExpression (hash=40147308): TransferValue - got raw value 'True'
System.Windows.Data Warning: 82 : BindingExpression (hash=40147308): TransferValue - user's converter produced 'Visible'
System.Windows.Data Warning: 89 : BindingExpression (hash=40147308): TransferValue - using final value 'Visible'

上面跟踪中的有趣行

System.Windows.Data Warning: 108 : BindingExpression (hash=40147308):   At level 1 - for String.IsEmpty found accessor <null>
System.Windows.Data Warning: 108 : BindingExpression (hash=40147308):   At level 1 - for EnumerableCollectionView.IsEmpty found accessor RuntimePropertyInfo(IsEmpty)

,所以您可以看到类型 String 确实没有 IsEmpty

so you can see that indeed type String does not have IsEmpty

for String.IsEmpty found accessor <null>

但是字符串的视图是 EnumerableCollectionView 确实具有 IsEmpty 并且绑定解析为相同的

but the view for the string is an EnumerableCollectionView which does have IsEmpty and the binding resolved to the same

for EnumerableCollectionView.IsEmpty found accessor RuntimePropertyInfo(IsEmpty)

这篇关于此XAML代码中的IsEmpty参考/成员在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 07:24