Underscore in menuitem (WPF) via CommandInfo

179 views
Skip to first unread message

Gauthier Craignou

unread,
Feb 26, 2016, 11:38:51 AM2/26/16
to Authoring Tools Framework
Hi, 

In my company, we are using ATF since several months now. It's great framework, but we still have some issues to use it perfectly.

I use the CommandInfo to declare a recent file info to display in the File menu under the section File Recently Used:

private void RegisterProject(RecentDocumentInfo project)
        {            
            CommandInfo recentProject = new CommandInfo(
                       project,
                       StandardMenu.File,
                       StandardCommandGroup.FileRecentlyUsed,
                       project.Uri.AbsolutePath,
                       project.Uri.AbsolutePath);

            _commandService.RegisterCommand(recentProject, this);
        }

The thing is that some of our paths contains underscores, but ATF uses the underscore to declare a shortcut.
Is there a way to display an underscore in the File Recently Used section or in a menu item generally?

Ron AtSony

unread,
Mar 1, 2016, 2:55:37 PM3/1/16
to Gauthier Craignou, Authoring Tools Framework
Hi Gauthier,

I had to do some research and I'm kind of confused about what specifies the accelerator key. I had always seen it specified using the '&' before the desired character, like in this MSDN example. But there are StackOverflow questions and answers that confirm your problem with the '_' in (some?) Windows Controls. The way to escape that is to use a double underscore, "__", instead. I can't actually reproduce this behavior in LevelEditor, so I wonder if there is some other way to turn off accelerator keys. (I'm also using Windows 8, in case that matters.)

I looked through ATF's RecentDocumentCommands to see what issues we may have run into like you did, with using file paths as menu items. The only problem we apparently ran into was with forward and back slashes creating unwanted child menus. Here's the key section:

                        string pathName = info.Uri.LocalPath;
                        // replace slashes, so command service doesn't create hierarchical menu; actual path
                        //  is set in our UpdateCommand method.
                        pathName = pathName.Replace("/", "-");
                        pathName = pathName.Replace("\\", "-");
                        var commandInfo = new CommandInfo(
                            info,
                            StandardMenu.File,
                            StandardCommandGroup.FileRecentlyUsed,
                            "Recent Files".Localize() + "/" + pathName,
                            "Open a recently used file".Localize(),
                            Keys.None);

                        commandInfo.ImageName = info.Pinned ? Resources.PinGreenImage : Resources.PinGreyImage;

                        commandInfo.ShortcutsEditable = false;
                        CommandService.RegisterCommand(
                            commandInfo,
                            this);

Please let us fellow ATF-users know how you fix this. I'm curious!

--Ron

--
You received this message because you are subscribed to the Google Groups "Authoring Tools Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to authoring-tools-fr...@googlegroups.com.
Visit this group at https://groups.google.com/group/authoring-tools-framework.
For more options, visit https://groups.google.com/d/optout.

Gauthier Craignou

unread,
Mar 2, 2016, 8:03:39 AM3/2/16
to Ron AtSony, Authoring Tools Framework
Hi Ron, 

I could fix the issue by replacing the underscore by a double underscore for the menuText. Thanks a lot.
I checked on Msdn and StackOverflow to find a way to disable the accelerator key the only way I found is to override the template of the MenuItem style. 
Thanks.

Gauthier

Cet e-mail a été envoyé depuis un ordinateur protégé par Avast.
www.avast.com
--
Gauthier Craignou
Reply all
Reply to author
Forward
0 new messages