代码之家  ›  专栏  ›  技术社区  ›  jedmao

有没有办法忽略XAML引发的Visual Studio错误?

  •  7
  • jedmao  · 技术社区  · 17 年前

    我知道你可以在暗藏中用这样的东西。。。

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

    但是有没有一种方法可以在XAML中实现这种类型的事情呢?

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

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

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

    错误1类型“FontFamily”不正确 可用作对象元素,因为它 公共无参数构造函数或

    和

    错误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的更好方法,否则我洗耳恭听!

    1 回复  |  直到 17 年前
        1
  •  2
  •   Chris Haines    15 年前

    你应该使用资源字典。以下是一个例子:

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