Ace
Ace

Reputation: 869

Xaml: C# How to keep style consistent

I'm working on a semi-large windows application using wpf and C# in VS 2010. While working on the xaml, I added a tag so that all buttons and datagrids are styled in the same way. I've copied and pasted this block into several of my .xaml files and that works fine. Of course the problem I'm running into now is that I've added to and changed the style several times.

What is the best way to keep style consistent between my different Windows? Is it subclassing, using Resources.resx, or another way enirely?

Upvotes: 0

Views: 367

Answers (2)

devman
devman

Reputation: 1549

yeah, if you were to create a new file called Resources.xaml and then add this to your Application.xaml file:

<Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
</Application.Resources>

then you should be able to reference the styles in the Resources.xaml from all the windows in your application.

Upvotes: 1

Damian
Damian

Reputation: 2789

If you define the style in the Application level ResourceDictionary (App.xaml), then it will automatically be inherited by your other XAML Windows/Controls.

Upvotes: 6

Related Questions