【问题标题】:Silverlight - Removing implicit styles from a sectionSilverlight - 从部分中删除隐式样式
【发布时间】:2011-10-30 20:16:29
【问题描述】:

我正在使用Silverlight toolkit 为我的整个应用程序设置样式。现在我需要从特定部分中删除隐式样式,这样它就不会干扰该部分中的其他样式。

基本上我想做这样的事情:

<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>

查看Silverlight工具包的源码,发现主题是通过合并资源字典来应用的:

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

主题文件包含一堆隐式样式的地方:

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

因此,我需要一种从特定部分中删除所有隐式样式的方法,但只能从该部分中删除。我需要这个的原因是因为这些样式会干扰第三方控件的样式(我认为这与precedence of the control styles 有关)。

这在 Silverlight 4 中可行吗?也欢迎解决方法。

提前致谢!

【问题讨论】:

    标签: c# silverlight xaml styles silverlight-toolkit


    【解决方案1】:

    您能做的最好的事情就是将 SL 工具包添加的隐式样式短路。例如,如果您像这样添加一个空样式:

    <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>
    

    然后空样式将阻止应用主题的样式,因为一次只能应用 1 个隐式样式。不过,您必须为 SL Toolkit 支持的每种元素类型执行此操作。

    【讨论】:

    • 太棒了!这实际上奏效了。 SL 一次只应用一种隐式样式。感谢您的帮助!
    【解决方案2】:

    设置样式属性为空

    Style="{x:Null}" 
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多