首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DynamicResource ResourceKey不工作

DynamicResource ResourceKey不工作
EN

Stack Overflow用户
提问于 2014-06-18 11:33:10
回答 1查看 884关注 0票数 0

如何在另一个_brush_backcolor001中引用ResourceDictionary?就像这样没用的:

代码语言:javascript
复制
<ResourceDictionary 

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:s="clr-namespace:System;assembly=mscorlib">

    <ResourceDictionary x:Key="_rd001">
        <SolidColorBrush x:Key="_brush_backcolor001">#FF8FBC8F</SolidColorBrush>
    </ResourceDictionary>

    <Style TargetType="Paragraph" x:Key="_stylePara001">
        <Setter Property="TextElement.Background">
            <Setter.Value>
                <DynamicResource ResourceKey="_brush_backcolor001" />
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-18 11:42:12

如果您想使用其他资源字典中的资源,可以通过指定ResourceDictionary.MergedDictionaries来合并它们。

代码语言:javascript
复制
<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary>
            <SolidColorBrush x:Key="_brush_backcolor001">#FF8FBC8F</SolidColorBrush>
        </ResourceDictionary>
    </ResourceDictionary.MergedDictionaries>
    <Style TargetType="Paragraph" x:Key="_stylePara001">
        <Setter Property="TextElement.Background">
            <Setter.Value>
                <DynamicResource ResourceKey="_brush_backcolor001" />
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

其中可以提取_brush_backcolor001以分离RecourceDictionary文件,然后通过Source属性引用

代码语言:javascript
复制
<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="path/to/separate/resouce/file.xaml"/>
</ResourceDictionary.MergedDictionaries>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24284446

复制
相关文章

相似问题

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