Search code examples
c#silverlightxamlstylessilverlight-toolkit

Silverlight - Removing implicit styles from a section


I'm using Silverlight toolkit to set the styling for my whole application. Now I need to remove the implicit styling from a specific section, so that it doesn't interfere with other styling in that section.

Basically I want to do something like this:

<theme:BureauBlackTheme>
    <StackPanel x:Name="LayoutRoot">
        <StackPanel><!-- Use the standard Bureau Black theme here --></StackPanel>
        <StackPanel><!-- I don't want any implicit styling on this section --></StackPanel>
    </StackPanel>
</theme:BureauBlackTheme>

Looking at the source code of the Silverlight toolkit, I found that themes are applied by merging resource dictionaries:

...
// Load the theme
ResourceDictionary resources = null;
using (stream)
{
    resources = ResourceParser.Parse(stream, true);
    owner.MergedDictionaries.Add(resources);
}
...

Where the theme files contain a bunch of implicit styles:

<!--ScrollBar-->
<Style  TargetType="ScrollBar">
    <Setter Property="MinWidth" Value="17" />
    ...

Therefore, I need a way to remove all the implicit styles from a specific section, but only from that section. The reason I need this, is because these styles are interfering with the styling of a third party control (I think this has to do with the precedence of the control styles).

Is this possible in Silverlight 4? Workarounds are welcome too.

Thanks in advance!


Solution

  • The best you could do is to short circuit the implicit Styles added by the SL Toolkit. For example, if you add an empty style like so:

    <theme:BureauBlackTheme>
        <StackPanel x:Name="LayoutRoot">
            <StackPanel><!-- Use the standard Bureau Black theme here --></StackPanel>
            <StackPanel>
                <!-- I don't want any implicit styling on this section -->
                <StackPanel.Resources>
                    <Style TargetType="ScrollBar" />
                </StackPanel.Resources>
            </StackPanel>
        </StackPanel>
    </theme:BureauBlackTheme>
    

    Then the empty Style will prevent the theme's Style from being applied, as only 1 implicit Style can be applied at a time. You'd have to do this for each element type supported by the SL Toolkit though.