Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinRT (Win 8) Store App XAML Bindings RelativeSourceMode FindAncestor missing?

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 regards Gope

like image 747
Gope Avatar asked Feb 19 '13 09:02

Gope


2 Answers

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" />
like image 168
Omer Raviv Avatar answered Dec 08 '22 00:12

Omer Raviv


There is no general solution for this lack afaik, for example you can't access ListViewItem properties in DataTemplate so you can't react on selection change elegantly. You should find workaround for each particular case until FindAncestor will be added(I can't believe that this absence is not just due to the lack of time)

like image 32
ixSci Avatar answered Dec 08 '22 01:12

ixSci