I've created a Recent Files menu item to which I bind a collection of recent file view models.
<MenuItem Header="_Recent Files" ItemsSource="{Binding RecentFiles}" Command="{x:Static pm:MainWindow.RecentFileListCommand}">
<MenuItem.ItemContainerStyle>
<Style>
<Setter Property="MenuItem.Header" Value="{Binding}"/>
<Setter Property="MenuItem.Command" Value="{x:Static pm:MainWindow.RecentFileOpenCommand}"/>
<Setter Property="MenuItem.CommandParameter" Value="{Binding FilePath}"/>
</Style>
</MenuItem.ItemContainerStyle>
</MenuItem>
I want the list numbered, and I want the numbers to be used as the shortcut (exactly how Visual Studio does it). My view models have a Number field and Name field. I override the ToString() method to return a header including the underscore:
return string.Format("_{0} {1}", Number, FilePath);
However, when bound, the underscore is seen as a literal and displays as part of the header text (not the shortcut). I also tried using HeaderStringFormat without luck:How can I get WPF to see the underscore as the shortcut and not a literal string?