好吧,经过一番调查,我找到了解决这个问题的适当办法。
使用以下代码,可以在模板中找到命名项:
if (treeViewItem != null)
{
//Get the header content presenter.
ContentPresenter header = treeViewItem.Template.FindName("PART_Header", treeViewItem) as ContentPresenter;
if (header != null)
{
//Find a CheckBox called "checkBoxName"
CheckBox cb = treeViewItem.HeaderTemplate.FindName("checkBoxName", header) as CheckBox;
}
}
<HierarchicalDataTemplate x:Key="templateName" ItemsSource="{Binding Path=someCollection}" ItemTemplate="{StaticResource someOtherTemplate}">
<TextBlock Text="{Binding Path=SomeProperty}" />
</HierarchicalDataTemplate>
我希望其他人会发现这些信息有用。