3

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!

alf
  • 18,372
  • 10
  • 61
  • 92

2 Answers2

4

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.

CodeNaked
  • 40,753
  • 6
  • 122
  • 148
  • Great! This actually worked. SL applies only one implicit style at a time. Thanks for your help! – alf Aug 23 '11 at 15:34
1

Set style property to null

Style="{x:Null}" 
Amyo
  • 66
  • 3
  • Thanks, but it doesn't work. Actually, neither of the stack panels has a style defined. The styles created by the theme are implicit (ie it sets a style for all textblocks) http://msdn.microsoft.com/en-us/library/ms743230.aspx – alf Aug 21 '11 at 18:03