C# 无法将属性绑定到嵌套在DataGrid HeaderTemplate内部的TreeView

C# 无法将属性绑定到嵌套在DataGrid HeaderTemplate内部的TreeView,c#,wpf,data-binding,datagrid,relativesource,C#,Wpf,Data Binding,Datagrid,Relativesource,我遇到了一个非常奇怪的问题。我无法确定如何将放置在fooditemscontrolviewmodel中的属性绑定到视图(fooditemscontrol): 型号: public interface IFolder { string FullPath { get; } string FolderLabel { get; } List<IFolder> Folders { get; } } 我已将跟踪添加到输出窗口以调试绑定: xmlns:diag="clr

我遇到了一个非常奇怪的问题。我无法确定如何将放置在
fooditemscontrolviewmodel
中的属性绑定到视图(
fooditemscontrol
):

型号:

public interface IFolder
{
    string FullPath { get; }
    string FolderLabel { get; }
    List<IFolder> Folders { get; } 
}
我已将跟踪添加到输出窗口以调试绑定:

xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
我在输出窗口中看到的是:

System.Windows.Data警告:78:BindingExpression(哈希=52875503): 使用根项目FooItemsControl激活(哈希=67071923)

System.Windows.Data警告:107:BindingExpression(哈希=52875503): 在级别0上,使用FooItemsControl.DataContext的缓存访问器: DependencyProperty(DataContext)

System.Windows.Data警告:104: BindingExpression(哈希=52875503):将级别0处的项替换为 FooItemsControl(hash=67071923),使用访问器 DependencyProperty(DataContext)

System.Windows.Data警告:101: BindingExpression(hash=52875503):从 使用DependencyProperty(DataContext)的FooItemsControl(哈希=67071923): FooItemsControlViewModel(哈希=28094463)

System.Windows.Data警告:107:BindingExpression(哈希=52875503):在级别1上使用FooItemsControlViewModel的缓存访问器。文件夹: RuntimePropertyInfo(文件夹)

System.Windows.Data警告:104:BindingExpression(哈希=52875503):使用访问器将级别1上的项替换为FooItemsControlViewModel(哈希=28094463) RuntimePropertyInfo(文件夹)

System.Windows.Data警告:101:BindingExpression(哈希=52875503):从中获取级别1的值 FooItemsControlViewModel(哈希=28094463)使用 RuntimePropertyInfo(文件夹):

System.Windows.Data警告:80: BindingExpression(hash=52875503):TransferValue-获取原始值

System.Windows.Data警告:89:BindingExpression (哈希=52875503):TransferValue-使用最终值

文件夹
属性未显示在
TreeView
中。有人知道我在
TreeView中看不到任何值的原因吗?(我以前看到过值)

为什么我需要
TreeView
HeaderTemplate
中?让我展示一幅图像:

为什么要将树视图中的ItemTemplate绑定到相对源?他们已经拥有TreeView的ItemsSource中某个项的datacontext,因此您应该使用该项作为绑定或该项的属性作为绑定。@GordonAllocman我已经尝试了您的变体,但没有相关源。数据未显示。这是一个非常奇怪的问题。如果您可以添加一些代码来显示您的数据模型,那么可能更容易看出哪里出了问题。例如,显示IFolder是什么以及它具有什么属性。此外,在不添加跟踪的情况下,输出窗口通常会通过默认值提供非常有用的绑定错误信息。为什么在datagrid的标头中有一棵树?@GordonAllocman,请参阅我更新的问题
<DataGrid ItemsSource="{Binding Persons}">            
   <DataGrid.Columns>
      <DataGridTextColumn  Binding="{Binding FirstName}" >
        <DataGridTextColumn.HeaderTemplate>
          ...
          <DataTemplate> 
             ...
              <PopUp> 
              <TreeView ItemsSource="{Binding DataContext.Folders, RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor},  diag:PresentationTraceSources.TraceLevel=High}" Margin="10">
        <TreeView.ItemTemplate>
           <HierarchicalDataTemplate ItemsSource="{Binding DataContext.FooFolders, RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}}" DataType="{x:Type toDelete:IFolder}">
              <TextBlock Text="{Binding FolderLabel}"/>
           </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>
      </TreeView>
    ...
    </PopUp>
 </DataTemplate>
 ...
xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"