0

我有以下 XAML。它是有效的(代码编译和运行都很好),但是 VS 给了我错误:“ XLS0505 Type 'FontImageSource' is used as a markup extension but does not derived from MarkupExtension

<Image Source="{FontImageSource Color={DynamicResource PrimaryColor}}"/>

我怎样才能抑制它.editorconfig?试过这个dotnet_diagnostic.XLS0505.severity = none,但它没有用。

4

1 回答 1

0

在 XAML 中,有一种特殊的语法允许代码执行附加规则并间接设置其他对象。请参阅有关标记扩展的官方 Microsoft 文档

所以在你的情况下,你可以设置FontImageSource如下

<Image >
    <Image.Source>
        <FontImageSource
        FontFamily="{DynamicResource MaterialFontFamily}"
        Glyph="{Binding xxx}"
        Size="44"
        Color="{DynamicResource PrimaryColor}"/>
    </Image.Source>
    
</Image>
于 2020-11-20T11:51:23.357 回答