How do I use XAML HexNumbers for Windows Store App icons (Segoe UI Symbol) in databound objects?

青春壹個敷衍的年華 提交于 2019-12-10 11:26:59

问题


I have a basic DataTemplate which I use to bind to the basic objects which expose several properties. These items are displayed in an ItemList. I am trying to ensure that the TextBlock which is bound to Icon, displays the symbol similar to  which would be stored in the object's Icon property.

<DataTemplate x:Key="Action180x180ItemTemplate">
    <Grid HorizontalAlignment="Left" Width="180" Height="180">
        <Border Background="OliveDrab">
            <TextBlock Text="{Binding Icon}" FontFamily="Segoe UI Symbol" FontSize="72" Padding="0,20,0,0" TextAlignment="Center" />
        </Border>
        <StackPanel VerticalAlignment="Bottom" Background="DarkOliveGreen">
            <TextBlock Text="{Binding Title}" Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource TitleTextStyle}" Height="30" Margin="15,0,15,0"/>
        </StackPanel>
    </Grid>
</DataTemplate>

The problem is that when the code is executed, the symbol is not displayed, but instead the raw value is. Does anyone have any idea on how to have the symbol display from a bound field (preferably without changing the Icon property from String to something else)?


回答1:


To write unicode characters directly inside XAML use this format: &#xhexcode;

To store unicode characters inside strings use this format: "\uhexcode"




回答2:


You can use Unicode character escape sequences in the c# string to achieve the binding. Something like the following:

DataContext = new { Icon = "\uE0C8", Title = "My Title" };

See Unicode character escape sequences for further details.



来源:https://stackoverflow.com/questions/14050255/how-do-i-use-xaml-hexnumbers-for-windows-store-app-icons-segoe-ui-symbol-in-da

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!