我正在尝试获取 Segoe UI 符号字体的所有字符。
我得到了它们,转换为字符,转换为十六进制值并作为项目添加到列表视图中。
因此,其他人可以将其用于 XAML 项目的十六进制值用作图标。
但问题是代码中的这个:我总是OverFlowException
在使用函数Convert.ToChar
。
代码运行正确,但是当索引变量大于最大字符值 65535 时,我得到了溢出异常。
但是如果你运行代码,你会看到,在 Segoe UI Symbol fontfamily 中有更多大于 65535 的字符。
也许我的方法是错误的,你可以建议我另一种方法。
MainWindow.xaml 文件:
<Grid Loaded="Grid_Loaded">
<ListView x:Name="listview">
<ListView.View>
<GridView>
<GridViewColumn Header="HexValue" />
</GridView>
</ListView.View>
</ListView>
</Grid>
MainWindow.xaml.vb 文件
Class MainWindow
Public glyph As GlyphTypeface
Dim characterMap As IDictionary(Of Integer, UShort)
Private Sub Grid_Loaded(sender As Object, e As RoutedEventArgs)
SymbolleriGetir()
End Sub
Public Sub SymbolleriGetir()
Dim segoeUiSymbol As FontFamily
For Each font As FontFamily In Fonts.SystemFontFamilies
Dim fontName As String
fontName = font.Source
If fontName = "Segoe UI Symbol" Then
segoeUiSymbol = font
End If
Next
For Each typeFace As Typeface In segoeUiSymbol.GetTypefaces
typeFace.TryGetGlyphTypeface(glyph)
If glyph IsNot Nothing Then
characterMap = glyph.CharacterToGlyphMap
Else
Continue For
End If
Next
For i As Integer = 0 To characterMap.Keys.Count
Dim index As Integer = characterMap.Keys.ElementAt(i)
Dim c As Char = Nothing
c = Convert.ToChar(index)
Dim charText As String = c.ToString()
listview.Items.Add(String.Format("&#x{0:x2};", System.Convert.ToUInt32(c)))
Next
End Sub
End Class