2009-07-27 76 views
7

我知道你可以像這樣的東西做在代碼隱藏...有沒有辦法忽略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的更好方法,否則我都是耳朵!

回答

2

您應該使用資源字典。這裏有一個例子:

<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> 
相關問題