有没有办法忽略XAML抛出的Visual Studio错误?

问题描述:

我知道你可以像这样的东西做在代码隐藏...有没有办法忽略XAML抛出的Visual Studio错误?

#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的更好方法,否则我都是耳朵!

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

<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像这样(假设他们是在一个资源文件夹):

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