首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >有没有一种方法可以让ResourceDictionary中的Freezable成为动态的DynamicResource?

有没有一种方法可以让ResourceDictionary中的Freezable成为动态的DynamicResource?
EN

Stack Overflow用户
提问于 2015-10-21 01:07:33
回答 1查看 227关注 0票数 3

我在Brushes.xaml中有这样的代码:

代码语言:javascript
运行
复制
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:SkinBox.Controls">
    <SolidColorBrush x:Key="{x:Static controls:Keys.BackgroundBrushKey}"
                     Color="{DynamicResource {x:Static controls:Keys.BackgroundColorKey}}" />
</ResourceDictionary>

在Generic.xaml中像这样使用它:

代码语言:javascript
运行
复制
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:SkinBox.Controls"
                    xmlns:system="clr-namespace:System;assembly=System">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Skins/Blue.xaml" />
        <ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Brushes.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

问题是wpf冻结了画笔,所以DynamicResource没有效果。

有没有一个干净的方法来解决这个问题?我只能想到令人讨厌的黑客。

EN

回答 1

Stack Overflow用户

发布于 2015-10-22 15:06:25

想一想解决办法:

代码语言:javascript
运行
复制
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:SkinBox.Controls">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Skins/Yellow.Colors.xaml" />
        <ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Brushes.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

这仍然不会提供真正的动态资源,但它会重新应用笔刷,以便它们在应用皮肤时更新。

消除了在每个蒙皮中复制笔刷的需要。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33242667

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档