views:

253

answers:

1

I've got this menu bound to an ObservableCollection called MainMenuPageItems, in which there are objects that have a Title property:

<Menu DockPanel.Dock="Top">
    <MenuItem Header="_File">
        <MenuItem Command="{Binding ExitCommand}" Header="E_xit" InputGestureText="Ctrl-X" />
    </MenuItem>
    <MenuItem Header="Code _Generation" ItemsSource="{Binding MainMenuPageItems}"
              ItemTemplate="StaticResource CodeGenerationTemplate"/>
</Menu>

This is my DataTemplate:

<DataTemplate x:Key="CodeGenerationTemplate">
    <MenuItem Header="{Binding Title}"/>
</DataTemplate>

But I get the error "The type DataTemplate does not have a public type converter class." What do I need to change so I don't get this error?

+2  A: 

Is it a typo that the ItemTemplate is missing the braces?

ItemTemplate="{StaticResource CodeGenerationTemplate}"
Cameron MacFarland
yes that was it thanks :-)
Edward Tanguay
Yeah that error message is misleading. It means WPF is taking the string "StaticResource CodeGenerationTemplate" and trying to turn it into a DataTemplate, but can't because there's no converter that can do that.
Cameron MacFarland