本文介绍了资源字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试全局使用资源字典,就像我不想在每个xaml页面中指定资源目录一样,
我试图在app.xaml中指定它,像这样的资源
< ResourceDictionary > < ; ResourceDictionary.MergedDictionaries > ="color:blue">< ResourceDictionary x : 名称 = 事物" 来源 = "Themes \ something.xaml" /> < ;/ ResourceDictionary.MergedDictionaries > style ="color:#a31515"> ResourceDictionary >如果只是在app.xaml中设置样式.我可以在任何xaml文件中引用该样式,但是我无法在资源中引用该样式字典.
有什么想法吗?我试图将"Something.xaml"的构建操作更改为内容,并且始终包含..在任何情况下都不是很幸运.
谢谢
解决方案
Hello Dotnetruler
我创建了一个WpfApplication2-放置了一个名为 themes-的文件夹 并在此文件夹中某物资源字典
无需在应用文件中提供名称.
像这样尝试
<Application x:Class="WpfApplication2.App" xmlns="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="themes\something.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>
I am trying to use a Resource dictionary globally, like i do not want to specify resource directory in each xaml page,
I tried to specify it in app.xaml, Resources like
<ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionaryx:Name="Something"Source="Themes\something.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary>If just set a style in app.xaml.. i can refer that in any xaml file, but i can not reference the style in the resource dictionary.
Any idea? I tried to change the Build action of "Something.xaml"as content and Always include.. not lucky in any of the case..
Thanks
解决方案
Hello Dotnetruler
I created a WpfApplication2 - placed a folder called themes - and in this folder the something resource dictionary
it ain't necessary to provide the name in the app file.
try it like this
<Application x:Class="WpfApplication2.App" xmlns="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="themes\something.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>更多推荐
资源字典
发布评论