我正在尝试将控件集中在 HierarchicalDataTemplate 中。不幸的是,我尝试绑定到模板中的控件失败了。这是我的代码:
<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>
当树视图项获得焦点时触发触发器,但 {Binding ElementName=EditBox} 失败并显示消息“找不到与引用'ElementName=EditBox,...的绑定的源”
如何修复此绑定?或者有没有更好的方法在 HierarchicalDataTemplate 中设置控件的焦点?
提前感谢您的帮助。