Question

I want to use ToggleButton styles from a theme available freely from: brianlagunas.com.

Problem is, if I apply the theme, not only my toggle button is styled, but every control is styled according to that theme.

How do I apply style explicitly from a theme designed to be used implicitly?

How the theme is loaded

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <!-- Light Theme -->
            <ResourceDictionary
             Source="Themes/Metro/Light/Metro.MSControls.Core.Implicit.xaml" />
            <ResourceDictionary
             Source="Themes/Metro/Light/Metro.MSControls.Toolkit.Implicit.xaml" />
            <!-- Dark Theme -->
            <!--
                <ResourceDictionary
                 Source="Themes/Metro/Dark/MetroDark.MSControls.Core.Implicit.xaml" />
                <ResourceDictionary
                 Source="Themes/Metro/Dark/MetroDark.MSControls.Toolkit.Implicit.xaml" />
            -->
        </ResourceDictionary.MergedDictionaries>
        <!-- Light Theme -->
        <SolidColorBrush x:Key="BackgroundKey" Color="#FFFFFF" />
        <!-- Dark Theme -->
        <!--<SolidColorBrush x:Key="BackgroundKey" Color="#FF181818" />-->
    </ResourceDictionary>
</Window.Resources>

How can I plan to use the theme:

<ToggleButton Content="ToggleButton" Width="150"
    Style="{StaticResource ToggleButtonStyle}"/>

Thanks.

Was it helpful?

Solution

The issue is that you load a ResourceDictionary that defines implicit style for ToggleButton.

Since the download page you linked is actually downloading a full solution, you have these options:

  1. Go to Metro.MSControls.Core.Implicit.xaml and copy the style of toggle button to your resources (the one with ToggleButtonStyle key, and don't forget to "bring" along all necessary brushes).
  2. Since there are no DLLs there, I'll assume you compiled the project/solution - so you can recompile it. If so, go to the same file and comment out this line:
<Style BasedOn="{StaticResource ToggleButtonStyle}"
    TargetType="{x:Type ToggleButton}" />

(one before last style in the file)

Recompile it and you're good to go.

I'd definitely choose option No. 2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top