显示外语导致"?"在WPF应用程序中

时间:2014-09-25 21:48:10

标签: c# wpf text encoding

我正在编写一个显示Navajo文本的应用程序,目前它正在使用“Navajo Verdana”字体。唯一的问题是声门停止显示为“?”。文本以常规文本块显示。

<TextBlock Text="{Binding Text}" 
                       Visibility="{Binding IsText, Converter={StaticResource BoolToVisibilityConverter} }"
                       Foreground="{Binding Tag.ScreenSettings.ForegroundColor, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" 
                       FontSize="22" 
                       FontFamily="{Binding Tag.ScreenSettings.CurrentFontFamily, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"
                       TextAlignment="Center"></TextBlock>

我意识到这通常是一个编码问题,我一直在尝试不同的编码,看它是否会改变任何东西。我使用过UTF8,ISO-8859-1和windows-1252。无论我使用什么编码,它仍然显示相同。

表示文件在MS Word中使用相同的字体显示正常。

以下是加载文件的代码:

public static Song LoadSong(string key)
    {
        var stream = File.OpenRead(key);
        var sr = new StreamReader(stream);
        var wholeSong = sr.ReadToEnd();

        var song = new Song(wholeSong, key);

        sr.Close();

        return song;
    }

以下是转换编码的代码:

public string ChangeEncoding(string text)
    {
        Encoding iso = Encoding.GetEncoding(1252);
        Encoding ascii = Encoding.UTF8;
        byte[] asciiBytes = ascii.GetBytes(text);
        byte[] utf8Bytes = Encoding.Convert(ascii, iso, asciiBytes);
        string msg = iso.GetString(utf8Bytes);
        return msg;
    }

我无法弄清楚正在发生什么,因为该字体的所有其他部分都在工作。任何人都有我可以尝试的想法吗?

0 个答案:

没有答案