2

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

1 Answer 1

12

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.