c# - Silverlight - 从部分中删除隐式样式

标签 c# silverlight xaml styles silverlight-toolkit

我正在使用 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 中可行吗?也欢迎解决方法。

提前致谢!

最佳答案

您能做的最好的事情就是将 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 支持的每种元素类型执行此操作。

关于c# - Silverlight - 从部分中删除隐式样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7125761/

相关文章:

c# - 内置函数 diff() 可用于 MathNet 中的矢量?

c# - 从 Silverlight 使用 REST 服务时出现问题

从子窗口绑定(bind) wpf

xaml - 使用ValueConverter相对于其父ActualHeight和另一个ViewModel属性放置一条线

c# - Visual Studio 2005 缓慢关闭

C# 派生泛型方法

c# - 如何隐藏 ColumnDefinition 的内容

c# - 在应用程序配置文件中找不到名为 'x' 的连接字符串...但它有效吗?

c# 如何在使用 list.Remove 时遍历列表中的每个项目

silverlight - EF5 Code First 和 RIA 服务 Silverlight "Object reference not set to an instance of an object"错误构建客户端