Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to ignore Visual Studio errors thrown by XAML?

I know you can do it in CodeBehind with something like this...

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

But is there a way to do this type of thing in XAML?

For example, I have the following in my App.xaml...

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

And it keeps throwing me these VS errors (even though it builds successfully)...

Error 1 Type 'FontFamily' is not usable as an object element because it is not public or does not define a public parameterless constructor or a type converter. 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

and...

Error 2 The type 'FontFamily' does not support direct content. 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

Unless you guys know a better way to store a FontFamily in your App.xaml, I'm all ears!

like image 347
jedmao Avatar asked Jul 27 '09 20:07

jedmao


1 Answers

You should use a resource dictionary. Here is an example:

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

And you should reference in you App.xaml like so (assuming they are in a Resources folder):

<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>
like image 118
Chris Haines Avatar answered Oct 28 '22 22:10

Chris Haines