views:

104

answers:

1

Hi there.

I must say I am quite new at WPF. I am building my first real application and I am facing some issues, at the moment with themes. This is the reason of my post.

In order to use a theme, such as ExpressionDark.xaml, I thought it was sufficient to include it at an application level. Therefore, in my App.xaml I added:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Skins/ExpressionDark.xaml" />
        </ResourceDictionary.MergedDictionaries>
        <myLib:Locator x:Key="Locator" />
    </ResourceDictionary>
</Application.Resources>

Here is the first question: I am not sure I am doing the right thing. Is it right to include the ExpressionDark.xaml into my application, in the "skins" folder and to reference it in that way? somewhere else I found something like "System.Windows.Theming.ExpressionDark" etc. Would that be the correct approach?

Anyway, by applying the theme with the above method, I can see almost all my controls being styled in a proper way; I say "almost all" because some of them, like DataGrids or TextBoxes, are not. I checked inside the ExpressionDark.xaml and I see there are styles defined for these components too. So why am I getting this strange behaviour?

I hope I explained everything clearly enough. Let me know if it is not.

Thanks in advance for any help you'll be able to provide.

Cheers,

G.

A: 

Hi ChrisF,

Ok, I think I've found out what's going on.

In App.xaml I set up the Style dictionary that I'd like my application to use. In my MainWindow.xaml, in the "local" resources, there was instead another dictionary that apparently was overriding the one inherited by the App.xaml.

I moved the local dictionary (the one in the Window) together with the App's MergedDictionaries and all my controls are being styled correctly.

I don't understand though the reason of this behaviour. The two dictionaries were not meant to clash, I supposed it was possible to use a general dict in App and a more specialized one in Window.

So, do you guys have any idea of what I was actually doing wrong?

Thanks again for your help, Cheers, Gianluca.

Gianluca Colucci
Since you had multiple styles the control used the first one it came to when looking up the visual tree. Since there was a definition in the Mainwindow.xaml for the TextBox is stopped there while other controls had to go farther to the App.xaml file. Those controls that do not find a style will use the default chrome.
Mike B
Thank you Mike B to point that out.
Gianluca Colucci