How to change text of context menu, tooltip of window button?

Docking/MDI for WPF Forum

Posted 7 months ago by Yuki
Version: 23.1.3
Avatar

Hello,

I'd like to change the following text.

- Context menu of floating document window

- Tooltip of floating document window button (Close/Minimamize/Maximize)

I want to change text of outside window of floating document window.

Is there any way?

Best regards, 

Comments (7)

Posted 7 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

You can update the text in the window title bar context menu and the window title bar button tooltips by customizing these string resources from the Shared Library:

  • UICommandMinimizeWindowText
  • UICommandMaximizeWindowText
  • UICommandRestoreWindowText
  • UICommandCloseWindowText
  • UICommandMoveWindowText
  • UICommandSizeWindowText


Actipro Software Support

Posted 7 months ago by Yuki
Avatar

Hello,

Thank you for your reply.

  • UICommandMinimizeWindowText
  • UICommandMaximizeWindowText
  • UICommandRestoreWindowText
  • UICommandMoveWindowText
  • UICommandSizeWindowText

I could not access these value.

Would you please check again?

Posted 7 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Please make sure sure you are looking at the SRName enumeration in the Shared Library, not the one for Docking/MDI.  Each product assembly has a SRName enumeration with their own string resources.  The ones you asked about here are related to core WindowChrome, which is all defined in the Shared Library.  The String Resource Browser utility lets you see all the string resources for each product assembly.


Actipro Software Support

Posted 7 months ago by Yuki
Avatar

Hello,

I could find it in the Shared Library.

I have another question.

Is is posible to change tooltip string dynamically? (such as UIAdvancedTabItemCloseButtonToolTip, UIToolWindowContainerCloseButtonToolTip)

I could not change it dynamically.

1. Open document window

2. Call `SR.SetCustomString(SRName.UIAdvancedTabItemCloseButtonToolTip.ToString(), "XXXXXX");`

--> Tooltip of close button was not changed.

Best regards,

Answer - Posted 7 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Some string resources like that one will get assigned in XAML as a control's template is applied, and will not be updated if the string resource value is updated later on.  Think of the string resource being assigned as a call to a static value in XAML.

It's important to set them prior to any UI being referenced or loaded so that your customized value is applied properly.  We generally recommend you do string resource updating in app startup before the main window loads.


Actipro Software Support

Posted 4 months ago by Yuki
Avatar

Hello,

When I customized the following string resource in order to change context menu captions of window, it seems to be applied to window button's tooltip(Close,Minimize,Maximize).

  • UICommandMinimizeWindowText
  • UICommandMaximizeWindowText
  • UICommandRestoreWindowText
  • UICommandMoveWindowText
  • UICommandSizeWindowText

  

I'd like to set separated caption to context menu and window button's tooltip.

It is because our customer want to use access key to operate context menu. (But it is not good that window button's tooltip has `_` text...)

Is there any solution?

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private static class NativeMethods
        {
            [DllImport("user32.dll")]
            [DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
            internal static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

            [DllImport("user32.dll")]
            [DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
            internal static extern IntPtr GetMenuStringA(IntPtr hMenu, uint uIdEnableItem, [MarshalAs(UnmanagedType.LPStr)] StringBuilder parm3, uint chmax, uint flag);
        }

        public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            SetContextMenuText();
        }

        private void SetContextMenuText()
        {
            var windowHandle = new WindowInteropHelper(this).Handle;
            var hMenu = NativeMethods.GetSystemMenu(windowHandle, false);

            var srNameList = new Dictionary<int, string>
            {
                {0, ActiproSoftware.Products.Shared.SRName.UICommandRestoreWindowText.ToString() },
                {1, ActiproSoftware.Products.Shared.SRName.UICommandMoveWindowText.ToString() },
                {2, ActiproSoftware.Products.Shared.SRName.UICommandSizeWindowText.ToString() },
                {3, ActiproSoftware.Products.Shared.SRName.UICommandMinimizeWindowText.ToString()},
                {4, ActiproSoftware.Products.Shared.SRName.UICommandMaximizeWindowText.ToString()},
                {6, ActiproSoftware.Products.Shared.SRName.UICommandCloseWindowText.ToString() },
            };

            foreach (var item in srNameList)
            {
                var menuString = new StringBuilder(250);
                _ = NativeMethods.GetMenuStringA(hMenu, (uint)item.Key, menuString, 250, 0x00000400);

                ActiproSoftware.Products.Shared.SR.SetCustomString(
                    item.Value,
                    menuString.ToString().Replace("&", "_").Replace("Alt+F4", string.Empty));
            }
        }
    }
Posted 4 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Instead of doing that, you could handle the WindowChrome.WindowSystemMenuOpening event.  That event's arguments passes the context menu that will open for the title bar and allows you to alter the items (or add new ones) before it shows.  You could update the text labels for each menu item there.


Actipro Software Support

The latest build of this product (v24.1.2) was released 4 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.