それはresourcedictionayファイルです:TopologyTree.xaml
<ResourceDictionary 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:autoDraw.ViewModel.Topology"
>
<HierarchicalDataTemplate x:Key="TopologyTreeBase" DataType="{x:Type local:Base}" ItemsSource="{Binding children}">
    <StackPanel Orientation="Horizontal">
        <CheckBox IsChecked="{Binding IsChecked}"></CheckBox>
        <TextBlock Text="{Binding name}"></TextBlock>
    </StackPanel>
</HierarchicalDataTemplate>
</ResourceDictionary>
サイドC#
objectTree.Resources = new ResourceDictionary();
objectTree.Resources.Source = new Uri("GUI/TopologyTree.xaml", UriKind.Relative);
objectTreeはTreeViewですが
しかし、それはうまくいきません。
私は次のようにうまくいきましたが、ここでDataTypeを再定義する必要があるので、あまり良くないと思います。
var resourceDictionary = new ResourceDictionary();
resourceDictionary.Source = new Uri("GUI/TopologyTree.xaml", UriKind.Relative);
objectTree.Resources.Add(
    new DataTemplateKey(typeof(ViewModel.Topology.Base)),
    resourceDictionary["TopologyTreeBase"] as HierarchicalDataTemplate
);
さらに、次のようにxamlのコンテンツをxmalウィンドウに直接入れてみました。これは機能しますが、動的にロードする必要があるため、xmalが適切であることが証明されました。
    <TreeView Name="objectTree" Grid.Column="4" Margin="3" Grid.Row="1" Grid.RowSpan="3">
        <TreeView.Resources>
            <HierarchicalDataTemplate DataType="{x:Type local:Topology.Base}" ItemsSource="{Binding children}">
                <StackPanel Orientation="Horizontal">
                    <CheckBox IsChecked="{Binding IsChecked}"></CheckBox>
                    <TextBlock Text="{Binding name}"></TextBlock>
                </StackPanel>
            </HierarchicalDataTemplate>
        </TreeView.Resources>
    </TreeView>
誰かが私がC#側でそれを簡単に使用する方法を手伝ってくれるでしょうか?
