How can I incorporate a data bound list of MenuItems to another MenuItem in WPF?
- by Julien Poulin
I have a 'File' MenuItem were I would like to display a list of recently opened files.
Here is the xaml I have now:
<MenuItem Header="File}">
<MenuItem Header="Preferences..." Command="{Binding ShowOptionsViewCommand}" />
<Separator />
<ItemsControl ItemsSource="{Binding RecentFiles}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<MenuItem Header="{Binding DisplayPath}" CommandParameter="{Binding}"
Command="{Binding Path=DataContext.OpenRecentFileCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}">
</MenuItem>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Separator />
<MenuItem Header="Exit" Command="{Binding CloseCommand}" />
</MenuItem>
However, when I use this code, there is a weird offset around the MenuItems and it looks like there is a container around them. How can I get rid of that?
Here is a screenshot of what it looks like: