有没有办法无视XAML抛出Visual Studio中的错误?
-
19-09-2019 - |
题
我知道你可以像这样的东西做在代码隐藏...
#pragma warning disable 67
...
#pragma warning restore 67
但是,有没有办法做到这种类型的事情在XAML?
例如,我有以下在我的App.xaml ...
<FontFamily x:Key="ExtendedFontFamily">Verdana</FontFamily>
和它保持扔我这些VS错误(即使它成功地生成)...
错误类型1 '的FontFamily' 不是 可用作因为它对象元素 是不公开的或没有定义 公共的无参数的构造函数或 类型 转换器。 C:\ Users \用户jed.hunsaker \文件\工作\次世代\ SRC \ ESO.App.Reporting \ ESO.App.Reporting.UI.Silverlight \ App.xaml中8 4 ESO.App.Reporting.UI.Silverlight
和...
错误2类型“的FontFamily”不 支持直接 内容。 C:\ Users \用户jed.hunsaker \文件\工作\次世代\ SRC \ ESO.App.Reporting \ ESO.App.Reporting.UI.Silverlight \ App.xaml中8 42 ESO.App.Reporting.UI.Silverlight
除非你们知道一个更好的方式来存储的FontFamily在你App.xaml中,我所有的耳朵!
解决方案
您应该使用资源字典。下面是一个例子:
<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>
不隶属于 StackOverflow