I am trying to focus a control within a HierarchicalDataTemplate. Unfortunately, my attempt to bind to a control within the template is failing. Here is my code:
<HierarchicalDataTemplate DataType="{x:Type TreeView_Experiment:BookmarkPage}">
<DockPanel>
<ToggleButton ... edited for brevity ... />
<Controls:EditableTextBlock x:Name="EditBox" Text="{Binding Path=Title}" VerticalAlignment="Center" IsEditable="True" Focusable="True"/>
</DockPanel>
<HierarchicalDataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsFocused, RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}}" Value="true">
<!-- The Value binding fails with the error: Cannot find source for binding with reference 'ElementName=EditBox -->
<Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=EditBox}"/>
</DataTrigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
The trigger fires when the treeview item gets the focus, but the {Binding ElementName=EditBox} fails with the message "Cannot find source for binding with reference 'ElementName=EditBox,..."
How can I fix this binding? Or is there a better way to set the focus of a control within a HierarchicalDataTemplate?
Thanks in advance for any help.