HierarchicalDataTemplate and DataType: XAML parser error


  • Hi,

    I'm trying to use in my MVVM SL5 application a TreeView with a HierarchicalDataTemplate with a couple of implicit data templates, one for each of my viewmodels. The code compiles fine, but at runtime I get a XamlParserException telling that "Items added to a dictionary must have a key". Of course I can add the key, but this defeats the whole purpose of implicit type-based templating, and how could I work around this in the context of a hierarchical template to be used as source of a TreeView? Could anyone help? Here is a dummy code fragment similar to my real-world XAML:

    <sdk:TreeView ItemsSource="{Binding Path=Segments,Mode=OneWay}">
        <Style TargetType="sdk:TreeViewItem">
          <Setter Property="IsExpanded" Value="{Binding Path=IsExpanded,Mode=TwoWay}"/>
          <Setter Property="IsSelected" Value="{Binding Path=IsSelected,Mode=TwoWay}"/>
          <Setter Property="FontWeight" Value="Normal"/>

        <sdk:HierarchicalDataTemplate DataType="dummy:Customer"
                        ItemsSource="{Binding Path=Products,Mode=OneWay}">

        <DataTemplate DataType="dummy:Product">


    Thursday, March 01, 2012 1:28 PM


  • you are using 



    HierarchicalDataTemplate to DataTemplate.. your solution works..

    HierarchicalDataTemplate is not supported for implicit conversion..

    Sunday, March 04, 2012 11:20 PM

All replies