I have the below situation:
<DataTemplate DataType="{x:Type tra:Presenter}">
<DockPanel>
<GroupBox>
<ie:DifferentControl DataContext="{Binding LocationSelectorPresenter}"
Visibility="{Binding PropertyOnTraPresenter, Converter={StaticResource boolToVis}}"/>
</GroupBox>
</DockPanel>
</DataTemplate>
How do I access a property on the DataTemplate's datatype, from something that has it's own DataContext?
I've attempted using FindAncestor
as below, but with no luck. (This came from this similar question, but I presume I'm missing something.)
Path=PropertyOnTraPresenter, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type tra:Presenter}}
I presume FindAncestor
is the wrong approach here, as DataTemplate
doesn't appear to be in the list of ancestor's considered.
System.Windows.Data Warning: 73 : Lookup ancestor of type tra:Presenter: queried StackPanel (hash=61829898)
System.Windows.Data Warning: 73 : Lookup ancestor of type tra:Presenter: queried ContentPresenter (hash=51997850)
System.Windows.Data Warning: 73 : Lookup ancestor of type tra:Presenter: queried Grid (hash=51537092)
System.Windows.Data Warning: 73 : Lookup ancestor of type tra:Presenter: queried GroupBox (hash=32646025)
System.Windows.Data Warning: 73 : Lookup ancestor of type tra:Presenter: queried DockPanel (hash=63418642)
System.Windows.Data Warning: 73 : Lookup ancestor of type tra:Presenter: queried ContentPresenter (hash=50027503)
System.Windows.Data Warning: 73 : Lookup ancestor of type tra:Presenter: queried ContentPresenter (hash=37861722)
System.Windows.Data Warning: 73 : Lookup ancestor of type tra:Presenter: queried AdornerDecorator (hash=8826739)
System.Windows.Data Warning: 73 : Lookup ancestor of type tra:Presenter: queried Border (hash=26352004)
System.Windows.Data Warning: 73 : Lookup ancestor of type tra:Presenter: queried SimplifierDialog (hash=6690366)
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor.......
I've also looked at this question, which seems to be my problem in reverse, but I can't make the solutions there fit, as it doesn't seem possible to give a DataTemplate an x:Name
.