Page 1 of 1

xaml textbox control

Posted: 06 Jul 2020, 07:58
by wang
hello.
I want to input some other language text info in Textbox Control,such as Chinese,Japanese..... Now the it just show rect symbol. how should I implement this function?
in addtion. I want to convert the textbox contextmenu "Paste" "Copy" to other language display.

Re: xaml textbox control

Posted: 06 Jul 2020, 18:37
by sfernandez
When you see those rects in the text is because the font used doesn't include the corresponding glyphs. You can set <TextBox FontFamily="Microsoft YaHei"> for example to use a font that includes Chinese scripts.

Anyway, I just verified our C# Application Framework is not providing an appropriate set of font fallbacks to avoid this situations, we should fix that for a future release.

In the meantime you can override it in your App.cs:
    partial class App : Application
    {
        protected override string[] GetFontFallbacks()
        {
            return new string[]
            {
                "Theme/Fonts/#PT Root UI",
                "Arial",
                "Segoe UI Emoji",           // Windows 10 Emojis
                "Arial Unicode MS",         // Almost everything (but part of MS Office, not Windows)
                "Microsoft Sans Serif",     // Unicode scripts excluding Asian scripts
                "Microsoft YaHei",          // Chinese
                "Gulim",                    // Korean
                "MS Gothic"                 // Japanese
            };
        }

        protected override Display CreateDisplay()
        {
            return new Win32Display();
        }

        protected override RenderContext CreateRenderContext()
        {
            return new RenderContextD3D11();
        }

        [STAThread]
        static void Main()
        {
            App app = new App();
            app.Uri = "App.xaml";
            app.Run();
        }
    }
I want to convert the textbox contextmenu "Paste" "Copy" to other language display.
You can set the ContextMenu property to whatever you want:
<TextBox>
  <TextBox.ContextMenu>
    <ContextMenu>
      <MenuItem Header="Cut" Command="ApplicationCommands.Cut"/>
      <MenuItem Header="Copy" Command="ApplicationCommands.Copy"/>
      <MenuItem Header="Paste" Command="ApplicationCommands.Paste"/>
    </ContextMenu>
  </TextBox.ContextMenu>
</TextBox>
This can be set locally in a particular TextBox, or using a <Setter> in a TextBox Style, so it can be shared in multiple text boxes. You can also use bindings in the Header of each menu item so they can change depending on the language of the application.