jed*_*mao 7 fonts xaml app.xaml visual-studio
我知道你可以在CodeBehind中用这样的东西来做...
#pragma warning disable 67
...
#pragma warning restore 67
Run Code Online (Sandbox Code Playgroud)
但是有没有办法在XAML中做这种事情?
例如,我在App.xaml中有以下内容......
<FontFamily x:Key="ExtendedFontFamily">Verdana</FontFamily>
Run Code Online (Sandbox Code Playgroud)
它一直在向我抛出这些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>
Run Code Online (Sandbox Code Playgroud)
您应该像这样在 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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1642 次 |
最近记录: |