WPF Implicit selection of template using DataTemplate, but outside of 'List'

后端 未结 1 455
被撕碎了的回忆
被撕碎了的回忆 2020-12-18 13:28

In my project, I have TreeView, which contains a tree of objects of various types (all subclassed from the same superclass).

To the right of my TreeView I would lik

相关标签:
1条回答
  • 2020-12-18 14:13

    Use a ContentControl

    <ContentControl Content="{Binding ElementName=treeView1, Path=SelectedItem}">
        <ContentControl.Resources>
            <DataTemplate DataType="{x:Type local:ViewModelA}">
                <local:ViewA />
            </DataTemplate>
            <DataTemplate DataType="{x:Type local:ViewModelB}">
                <local:ViewB />
            </DataTemplate>
        </ContentControl.Resources>
    </ContentControl>
    
    0 讨论(0)
提交回复
热议问题