【问题标题】:How do I use XAML HexNumbers for Windows Store App icons (Segoe UI Symbol) in databound objects?如何在数据绑定对象中将 XAML HexNumbers 用于 Windows 应用商店应用程序图标(Segoe UI 符号)?
【发布时间】:2012-12-27 06:15:26
【问题描述】:

我有一个基本的DataTemplate,我用它来绑定到公开几个属性的基本对象。这些项目显示在ItemList 中。我试图确保绑定到Icon 的TextBlock 显示类似于 的符号,该符号将存储在对象的Icon 属性中。

<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>

问题是当代码执行时,符号不显示,而是原始值显示。有没有人知道如何从绑定字段显示符号(最好不要将 Icon 属性从 String 更改为其他内容)?

【问题讨论】:

    标签: windows xaml microsoft-metro


    【解决方案1】:

    要直接在 XAML 中写入 unicode 字符,请使用以下格式: 十六进制代码;

    要在字符串中存储 unicode 字符,请使用以下格式: "\u十六进制代码"

    【讨论】:

      【解决方案2】:

      您可以在 c# 字符串中使用 Unicode 字符转义序列来实现绑定。类似于以下内容:

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

      更多详情请参阅Unicode character escape sequences

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-05-02
        • 2015-09-05
        • 2012-10-11
        • 2012-09-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多