问题描述
有没有人知道XAML绑定中FindAncestor的新方法是什么?查看RelativeSourceMode()只有参考自己或TemplatedParent的选项。 FindAncestor没了我想知道为什么以及使用FindAncestor修复的问题的典型解决方案是什么。最好的问候
Gope
为什么缺少?不知道,但我怀疑有一个解释,除了微软没有足够的时间实现所有的功能及时。
一个简单的解决方法是使用 ElementName ,如下所示:
Binding = {ElementName = TheNameOfTheAncesor,Path = DataContext.TheViewModelProperyIWantToBindTo}
另外,要为您想要的祖先添加一个 x:Name 属性FindAncestor绑定指向:
< TextBlock x:Name =TheNameOfTheAncestor/>
does anybody know what the "new way" of FindAncestor in XAML bindings is? Looking at the RelativeSourceMode (http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.data.relativesourcemode) there are only options left for referencing self or the TemplatedParent. FindAncestor is gone. I'd like to know why and what are the typical solutions to the problems I fixed using FindAncestor.
Best regardsGope
Why it's missing? No idea, but I doubt there's an explanation other than "Microsoft did not have enough time to implement all the features in time".
An easy work-around is to use ElementName instead, as in:
Binding={ ElementName=TheNameOfTheAncesor, Path=DataContext.TheViewModelProperyIWantToBindTo }
And to add an x:Name attribute to the ancestor you wanted your FindAncestor binding to point to:
<TextBlock x:Name="TheNameOfTheAncestor" />
这篇关于WinRT(Win 8)Store App XAML Bindings RelativeSourceMode FindAncestor missing?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!