Theme only partially applying

May 20, 2010 at 11:20 PM
Edited May 21, 2010 at 3:25 PM

This is driving me crazy because I can't figure out what the problem is. Moreover, I have the sneaking suspicion this is due to some deeper problem that happened a while ago. The problem is this: when I attempt to use the ExpressionDark theme, only some of it ends up getting applied (in particular, scroll bars, combo box) but things like buttons, check boxes and menu backgrounds keep looking like the default Aero style. Oddly, the menu selection highlight gets changed, as does the menu foreground color so I get this really odd effect of a dark highlight appearing over a mostly white menu.

When I say i have the suspicion this happened in the past, it's because I did something weird once with as I recall the Vista magnifier tool (I don't recall what, but I remember it changed EVERYTHING on my system--perhaps it was some font or dpi setting or something. When I changed it back, it didn't revert completely and I was left with an odd font for all of my files and everywhere in every program. Anyhow somehow I managed to get this to change back (I think I fiddled with font settings or something) but it still didn't end up feeling exactly right.

So I mention this of course because it may not be a bug in the theme, but if anyone knows what I can do to fix this please tell! I tried completely removing and reinstalling the .NET framework, but it still happens just the same.

Thanks for any help!!

Update: So it turns out it has nothing to do with that earlier problem I experienced as it is also happening on my netbook. So the question is what is wrong with my application that is preventing the theme from working properly? I have referenced WPFToolkit.dll and referenced ExpressionDark.xaml from my App.xaml's ResourceDictionary.

May 22, 2010 at 2:04 PM

Okay so I've got it mostly working by creating an empty project with no other dependencies, but still the ContextMenu is not looking right. As I mentioned, the menu items appear correct only when the mouse is hovering over them, but the menu itself is still coming from the system theme.

Is the theme supposed to support ContextMenus? Is there something specific I have to do to get them to work?

May 22, 2010 at 6:22 PM

I've come to the conclusion the theme does not actually support ContextMenu styling. Why, I don't know.

I managed to get it roughly working by adding some additional elements to the theme resource file. Here is what I added, in case anyone else wants to pursue this, though I have given up on it:

<Style
        TargetType="{x:Type ContextMenu}">
        <Setter
            Property="SnapsToDevicePixels"
            Value="True" />
        <Setter
            Property="OverridesDefaultStyle"
            Value="True" />
        <Setter
            Property="Grid.IsSharedSizeScope"
            Value="true" />
        <Setter
            Property="HasDropShadow"
            Value="True" />
        <Setter
            Property="DockPanel.Dock"
            Value="Top" />
        <Setter
            Property="Padding"
            Value="0,2,0,2" />
        <Setter
            Property="Grid.IsSharedSizeScope"
            Value="true" />
        <Setter
            Property="Template">
            <Setter.Value>
                <ControlTemplate
                    TargetType="{x:Type ContextMenu}">
                    <Grid
                        x:Name="SubMenu"
                        Margin="0,0,3,3"
                        SnapsToDevicePixels="True">
                        <Border
                            x:Name="SubMenuBorder"
                            Background="{DynamicResource LightBrush}"
                            BitmapEffect="{DynamicResource PopupDropShadow}"
                            BorderThickness="1"
                            Opacity="0.8">
                            <Border.BorderBrush>
                                <SolidColorBrush
                                    Color="{DynamicResource WhiteColor}" />
                            </Border.BorderBrush>
                        </Border>
                        <StackPanel
                            IsItemsHost="True"
                            KeyboardNavigation.DirectionalNavigation="Cycle" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger
                            Property="IsEnabled"
                            Value="false">
                            <Setter
                                Property="Foreground"
                                Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
I've decided to just use the buttons and checkboxes and stuff and stick to the system default for menus.