【问题标题】:Is there a way to ignore Visual Studio errors thrown by XAML?有没有办法忽略 XAML 引发的 Visual Studio 错误?
【发布时间】:2010-11-14 11:53:46
【问题描述】:

我知道你可以在 CodeBehind 中用这样的东西来做到这一点......

#pragma warning disable 67
...
#pragma warning restore 67

但是有没有办法在 XAML 中做这种事情?

例如,我的 App.xaml 中有以下内容...

<FontFamily x:Key="ExtendedFontFamily">Verdana</FontFamily>

而且它不断向我抛出这些 VS 错误(即使它构建成功)...

错误 1 ​​类型“FontFamily”不是 可用作对象元素,因为它 不公开或未定义 公共无参数构造函数或 类型 转换器。 C:\Users\jed.hunsaker\Documents\Work\NextGen\src\ESO.App.Reporting\ESO.App.Reporting.UI.Silverlight\App.xaml 8 4 ESO.App.Reporting.UI.Silverlight

还有……

错误 2 'FontFamily' 类型不 直接支持 内容。 C:\Users\jed.hunsaker\Documents\Work\NextGen\src\ESO.App.Reporting\ESO.App.Reporting.UI.Silverlight\App.xaml 8 42 ESO.App.Reporting.UI.Silverlight

除非你们知道在 App.xaml 中存储 FontFamily 的更好方法,否则我会全力以赴!

【问题讨论】:

    标签: visual-studio xaml fonts app.xaml


    【解决方案1】:

    您应该使用资源字典。这是一个例子:

    <ResourceDictionary
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    
        <FontFamily x:Key="ExtendedFontFamily">Verdana</FontFamily>
    </ResourceDictionary>
    

    您应该像这样在 App.xaml 中引用(假设它们位于 Resources 文件夹中):

    <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    x:Class="SilverlightApplication3.App"
                    >
        <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="Resources/Fonts.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Application.Resources>
    </Application>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-30
      相关资源
      最近更新 更多