Okay. So I want my application to display in its main menu the “Save” and “Save As…” items just like Visual Studio does; i.e. “Save {current file}” and “Save {current file} As…”
I would also like to have the normal access keys (“S” and “A”, respectively).
I’ve come up with two solutions, but neither is very desirable.
-
Instead of creating the main menu exclusively in xaml, I could
create it all in the MainWindowViewModel so I’d have full control over what goes into the generated MenuItems. However, I feel that this would be a violation of MVVM (which I’m attempting to abide by very strictly this time around) as I would have to include references to each MenuItem’s Icon in the ViewModel. Plus it seems a little messy. -
I can stipulate the header of just these two specific MenuItems (and perhaps future ones) like so, but then I end up getting a MenuItem that not only has a underscore in the header, but also does not contain an access key.
<MenuItem Header="{Binding CurrentFileName}"
HeaderStringFormat="Save {0} _As...">
What should I do?
Whelp, figured it out. At least about how to get it done with the whole main menu described in XAML. Just made the header content an AccessText control instead of a string and it works like a charm.