首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >棱镜中的动态资源

棱镜中的动态资源
EN

Stack Overflow用户
提问于 2012-05-10 06:53:25
回答 1查看 1.3K关注 0票数 1

我不能得到一个按钮风格的工作在一个棱镜4.0应用程序四个模块。以下是Module2中xaml视图文件中的按钮元素:

代码语言:javascript
运行
复制
<Button Name="add" Width ="60" Style="{DynamicResource Red}"  Click="add_Click"> Add</Button>

该应用程序构建和运行,但按钮的颜色没有出现。我已经在Shell模块的主题文件夹中的Generic.xaml文件中定义了样式。这应该是可以在模块之间放置要共享的样式的地方。在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:Shell.Controls" 
    xmlns:wc="clr-namespace:System.Windows.Controls;assembly=PresentationFramework">

 <Style 
   x:Key="{ComponentResourceKey 
    TypeInTargetAssembly={x:Type wc:Button},
    ResourceId=Red}"
    TargetType="wc:Button">
    <Setter Property="Foreground" Value="Red" />
  </Style>
</ResourceDictionary>

我在Shell项目的Properties文件夹中的AssemblyInfo.cs文件中也有必要的参考。这将指示Prism应用程序解析来自Prism Generic.xaml文件的所有样式引用:

代码语言:javascript
运行
复制
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]

这些仍然是由我开始使用的Prism WPF统一模板提供的原始设置,由David的博客[http://blogs.msdn.com/b/dphill/archive/2011/01/16/prism-4-0-template-pack-now-available.aspx]提供。该模板附带了一些已经在Generic.xaml中的样式,但是裸模板应用程序只将这些样式用于Shell程序集中的控件,因此出现了上述参数"None“和"SourceAssembly”。

由于我试图定义在Shell模块以外的模块中使用的样式,所以我将以下ThemeInfo属性添加到AssemblyInfo.cs of Module1和Module2L中

代码语言:javascript
运行
复制
[`assembly: ThemeInfo(ResourceDictionaryLocation.ExternalAssembly, ResourceDictionaryLocation.ExternalAssembly)]`

我尝试在ThemeDictionary中向App.xaml添加一个App.xaml扩展&没有结果。

代码语言:javascript
运行
复制
    <Application.Resources>
    <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="{ThemeDictionary MyApp}"/>
    </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    </Application.Resources>

还在App.xaml中尝试了这样的包url & got“无法定位资源”错误。

代码语言:javascript
运行
复制
    <Application.Resources>
    <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="pack://application:,,,/MyApp;Shell/Themes/Generic.xaml"/>
    </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    </Application.Resources>

对于缺少什么,有什么想法或想法吗?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-16 19:03:24

更新:我是通过技术支持从微软的Microsoft那里得到答案的。两个变化:

其中之一是在Generic.xaml中,将样式定义更改为:

代码语言:javascript
运行
复制
    <Style
x:Key="Red"
TargetType="Button">
    <Setter Property="Foreground" Value="Red" />
    </Style>

另一个变化是对App.xaml的修改:

代码语言:javascript
运行
复制
  <Application.Resources>

    <ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
     <ResourceDictionary
Source="pack://application:,,,/Shell;component/Themes/Generic.xaml"/>
     </ResourceDictionary.MergedDictionaries>
     </ResourceDictionary>
    </Application.Resources>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10528847

复制
相关文章

相似问题

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