tags:

views:

160

answers:

1

Is it possible to store style definitions in one file (XXXXX.css) and then to use this file in XAML files?

+5  A: 

It's not called CSS, but you can create a resource dictionary in a separate file like this:

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;

    <Style x:Key="MyStyledButton" TargetType="Button">
        .
        Put the details of your style here, just like you would for a normal style.
        .
    </Style>

</ResourceDictionary>

Then you can import that resource dictionary into other XAML files by setting the resources on a class, for example if you have a Window class, you would do:

<Window.Resources>
    <ResourceDictionary Source="MyStylesFile.xaml" />
</Window.Resources>

Now that style takes effect for any control within the window just as if you had specified the style directly in the window resources.

Simon P Stevens
Thank you very much!
den123