在我的 WPF 应用程序中,我在 XAML 中定义了一个 TreeView 控件。我添加了一个 TreeView.Resources 部分,如下所示:
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:FileGroup}" ItemsSource="{Binding protXMLFiles}">
<TextBlock Text="{Binding Path=groupName}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:protXMLFile}" ItemsSource="{Binding}">
<TextBlock Text="{Binding Path=filename}"/>
</HierarchicalDataTemplate>
</TreeView.Resources>
上面,我在顶部用一行定义了“本地”命名空间:
<Window x:Class="FileGrouper.SPWindow" ... xmlns:local="clr-namespace:FileGrouper"...>
当我尝试在 Visual Studio 设计器中加载我的 XAML 时,我在设计器顶部收到一条警告:“文档包含在更新设计器之前必须修复的错误。单击此处打开错误列表” ; 错误列表中的相关错误消息为:“类型引用找不到名为'FileGroup'的公共类型”。编译后错误列表中的所有错误都清除了,应用程序运行没有问题。
尽管如此,除非删除 <TreeView.Resources> 块,否则我仍然无法使用 XAML 设计器。这是怎么回事,我该如何解决?