【问题标题】:Using Unicode characters in C# controls在 C# 控件中使用 Unicode 字符
【发布时间】:2010-01-26 15:56:09
【问题描述】:

我想将希腊字母 omega (U+03A9) 添加到我放置在表单上的标签中。我已经切换了表单的编码,但是如何设置标签的内容,以便出现 omega 而不是 UTF 字符代码。

所以采用这个 XAML

<Label Height="25">U+03A9</Label>

我希望将 U+03A9 转换为 omega

在后面的代码中我相信我可以做类似的事情

targetEncoding = Encoding.getEncoding(utfEncoding);
lblOmega.Content = targetEncoding.getBytes("\u03A9");

但我想知道我是否可以在 XAML 中严格执行此操作

【问题讨论】:

  • “UTF 字符码”是什么意思?你能给我们展示一个小的示例应用吗?

标签: c# xaml unicode


【解决方案1】:

只需添加文字符号 Ω 作为控件的文本。无需进一步修改。

lblOmega.Text = "Ω";

【讨论】:

  • 如此明显,我什至没有想到这一点。最后只是将字符直接粘贴到 XAML 中。谢谢。
【解决方案2】:

你的意思不是很清楚(你以什么方式切换了表单的编码?)但这对我来说很好:

using System;
using System.Windows.Forms;

class Test
{
    static void Main()
    {
        Form form = new Form
        {
            Controls =
            {
                new Label
                {
                    Text = "-> \u03a9 <-"
                }
            }
        };
        Application.Run(form);
    }
}

【讨论】:

    【解决方案3】:

    Ctrl+C 然后 Ctrl+V, 在 Visual Studio 中将字符映射中的“omega”符号复制到 XAML

    <TextBlock FontStyle="Italic" Text=" ꞷ" />
    <TextBlock FontStyle="Italic" Text=" Ω" />
    

    Character Map in Windows

    上面写的C#怎么做。这是 WPF 中 XAML 的解决方案

    【讨论】:

      【解决方案4】:

      使用 html unicode 实体对我有用:

                      <Label Content="&#937; :" />
      

      【讨论】:

        猜你喜欢
        • 2017-11-16
        • 1970-01-01
        • 2016-04-04
        • 2022-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-11
        • 2023-03-27
        相关资源
        最近更新 更多