【问题标题】:Suppress error in xaml using .editorconfig使用 .editorconfig 抑制 xaml 中的错误
【发布时间】:2021-03-03 19:00:54
【问题描述】:

我有以下 XAML。它是valid(代码编译和运行都很好),但是 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,但没用。

【问题讨论】:

    标签: visual-studio xaml xamarin editorconfig error-suppression


    【解决方案1】:

    在 XAML 中有一种特殊的语法,允许代码执行附加规则并间接设置其他对象。请参阅official Microsoft Docs on Markup Extensions

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

    <Image >
        <Image.Source>
            <FontImageSource
            FontFamily="{DynamicResource MaterialFontFamily}"
            Glyph="{Binding xxx}"
            Size="44"
            Color="{DynamicResource PrimaryColor}"/>
        </Image.Source>
        
    </Image>
    

    【讨论】:

    • 这就是重点,所以我使用它作为标记扩展。 Xamarin 组织的成员建议并确认错误无效:github.com/xamarin/Xamarin.Forms/issues/… 再次 xaml 工作正常。问题是,如何抑制这个无效异常,而不是如何编写 xaml 使这个异常不发生。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-05
    • 2014-05-30
    • 1970-01-01
    相关资源
    最近更新 更多