0
我正在使用自定義字體來顯示我的WPF應用程序中的圖標。我寫了一個小小的演示應用程序,將相應的「字符」旁邊的圖標呈現給我。C#自定義字體值被解釋爲字符串而不是單個值
不幸的是,C#不會將我的迭代的結果字符串解釋爲單個字符,而是字符串。
代碼:
private string _BaseString = "";
public IconsPane()
{
InitializeComponent();
InitIcons();
}
private void InitIcons()
{
string[] hex = new string[16] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
string output = "";
foreach (string a in hex)
{
foreach (string b in hex)
{
foreach (string c in hex)
{
output = a + b + c;
CreateIcon(output);
}
}
}
}
private void CreateIcon(string output)
{
StackPanel st = new StackPanel();
st.Margin = new Thickness(5);
Button ILabel = new Button();
ILabel.Style = (Style)FindResource("ContentButtonPlain");
ILabel.Content = _BaseString + output + ";";
TextBox IDesc = new TextBox();
IDesc.Text = (string)ILabel.Content;
IDesc.HorizontalAlignment = HorizontalAlignment.Center;
st.Children.Add(ILabel);
st.Children.Add(IDesc);
IconDashboard.Children.Add(st);
}
相反,我想有每個圖標是後面的字符串:
預期輸出:
預期輸出的屏幕截圖是從XAML代碼所採取的設計師
<Button Margin="5 0 5 0"
Style="{StaticResource ContentButtonPlain}"
Content="" />
在這種情況下,圖標以正確的方式是公認的。
在C#中,unicode字符轉義序列被寫爲'\ uXXXX',而不是在XML/XAML中使用的'&#xXXXX;'。 – Clemens
恩,你沒有真正的幫助。 (char)xxx都沒有幫助,我需要能夠正確顯示&#xEXXX;和圖標本身。我的主要問題是要了解我如何才能使a + b + c成爲正確的\ u字符。 – Richard