Share via

DocumentViewer "PART_FindToolBarHost" - change default language

Luka Ciglar 21 Reputation points
2020-04-08T17:13:09.45+00:00

Hi,

I would like to use DocumentViewer for print preview of my XPS files. However, the ContentPresenter control known as PART_FindToolBarHost embedded inside DocumentViewer doesn't recognize my Windows language settings, so by default It's everything in English - Textbox watermark, menu names, tooltips etc.

I want It to be in my language (Slovenian) or be able to edit template via VS Blend to fix everything - which unfortunally I couldn't do It.

Here is a screenshot of this control in DocumentViewer:
7194-brez-naslova.png

Is there ANY way I could achieve this ?

Regards, Luka

Developer technologies | Windows Presentation Foundation
0 comments No comments

Answer accepted by question author

gekka 14,146 Reputation points MVP Volunteer Moderator
2020-04-09T03:49:17.533+00:00

Hi LukaCiglar,

The string is hard coded in %windir%\Microsoft.NET\Framework\v4.0.30319\WPF\(language)\PresentationUI.resources.dll.
If there are no Slovenian resources, it will be in English.

private void DocumentViewer_Loaded(object sender, RoutedEventArgs e)
{
    var dv = (DocumentViewer)sender;
    var host = dv.Template.FindName("PART_FindToolBarHost", dv) as ContentControl;
    var content = host?.Content as Control;
    if (content == null)
    {
        return;
    }

    var label = content.FindName("FindTextLabel") as Label;
    if (label != null)
    {
        label.Content = label.Name;
    }

    var textBox = content.FindName("FindTextBox") as TextBox;
    if (textBox != null)
    {
        textBox.ToolTip = textBox.Name;
    }

    var prev = content.FindName("FindPreviousButton") as Button;
    if (prev != null)
    {
        prev.ToolTip = prev.Name;
    }

    var @next = content.FindName("FindNextButton") as Button;
    if (prev != null)
    {
        @next.ToolTip = next.Name;
    }

    var menu = content.FindName("OptionsMenu") as Menu;
    if (menu != null)
    {
        var menuItem = menu.Items[0] as MenuItem;
        menuItem.ToolTip = menuItem.Name;

        foreach (MenuItem submenu in menuItem.Items)
        {
            submenu.Header = submenu.Name;
        }
    }
}

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.