转换器返回Segoe MDL2图标绑定后不起作用 [英] Converter returning Segoe MDL2 icon after binding does not work

查看:134
本文介绍了转换器返回Segoe MDL2图标绑定后不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将PlayerFramework.MediaPlayer.CanPause属性绑定到Windows 10通用应用程序中的按钮。这可以使用默认字体,但是当我切换到Segoe MDL2以获得这些花哨的图标时,该按钮显示垃圾。

I'm trying to bind the PlayerFramework.MediaPlayer.CanPause Property to a Button in my windows 10 universal app. This works using the default font, but when I switch to Segoe MDL2 to get those fancy icons the button shows garbage.

<mmppf:MediaPlayer x:Name="mediaElement">

...

<Button Name="btnPlay" 
        Style="{StaticResource transportStyle}"  Content="{Binding CanPause, ElementName=mediaElement, Converter={StaticResource CanPauseToPlayPauseConverter}}"/>

这是从转换器:

public object Convert(object value, Type targetType, object parameter, string language)
    {
        bool canPause = (bool)value;
        if (canPause)
            return @"&#xE769;";
        // "play"
        return "&#xE102;";
    }

...此按钮样式:

<Style x:Name="transportStyle"  TargetType="Button">
       <!-- <Setter Property="FontFamily" Value="Segoe MDL2 Assets" />-->
</Style>

禁用Setter属性后,该按钮显示预期值

After disabling the Setter property the button shows the expected value

&#xE102;

直接设置为按钮内容,显示播放符号。

which, directly set as the button content, shows the play symbol.

任何想法为什么不起作用?

Any ideas why this doesn't work?

编辑:从字符表中复制字符并返回它可以正常工作。

edit: Copying the character from the character table and returning it does work.

推荐答案

&#xE102; 是XML中的unicode字符转义序列(因此也在XAML中)。在C#中,它被写为 \\\

&#xE102; is a unicode character escape sequence in XML (and hence also in XAML). In C# it is written as \uE102.

所以转换器应该返回字符串(或字符) C#unicode字符转义序列

So the converter should return strings (or characters) with proper C# unicode character escape sequences:

public object Convert(object value, Type targetType, object parameter, string language)
{
    return (bool)value ? "\uE769" : "\uE102";
}

这篇关于转换器返回Segoe MDL2图标绑定后不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆