在 WindowsPhone 7 应用中使用外部 ResourceDictionary [英] Use an External ResourceDictionary in a WindowsPhone 7 app
问题描述
我正在尝试在外部 dll 中创建一个名为 DataTemplate.xaml 的 ResourceFile,并在 WP7 页面中使用它.当我在页面的标题中执行以下操作时,出现错误
I am trying to create an ResourceFile Called DataTemplate.xaml in an external dll and use that in a WP7 page. When I do the following in the header of my Page I get an error
<代码><ResourceDictionary Source="pack://application:,,,/WP7SharedClassLibrary;component/DataTemplate.xaml"/>
错误是当前项目不支持将‘应用程序’作为包 URI 的权限组件."
The error is "Current project does not support 'application' as the authority component of the pack URI."
有没有其他人遇到过这个问题并解决了这个问题?
Has anyone else come across this and solved this?
推荐答案
我已设法使用以下步骤使其正常工作:
I've managed to get this to work using the following steps:
- 使用名为WP7ExternalResourcesTest"的Windows Phone 应用程序"应用程序模板创建了一个标准的 WP7 应用程序.
- 使用名为WP7ExternalResourcesTestLibrary"的Windows Phone 类库"模板向同一解决方案添加了一个项目.
- 从库项目中删除了默认的 Class.cs 文件.
- 使用XML 文件"模板添加了一个名为External.xaml"的文件,并将构建操作"设置为页面".
将以下 XAML 添加到新的 XAML 文件中:
- Created a standard WP7 application using the "Windows Phone Application" application template called "WP7ExternalResourcesTest".
- Added a project to the same solution using the "Windows Phone Class Library" template called "WP7ExternalResourcesTestLibrary".
- Removed the default Class.cs file form the library project.
- Added a file called "External.xaml" using the "XML file" template and set the "Build Action" to "Page".
Added the following XAML to the new XAML file:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="ForegroundBrush" Color="Red" />
</ResourceDictionary>
在 WP7ExternalResourcesTest 中,打开 App.xaml 并将 Application.Resources
部分更改为以下内容:
In WP7ExternalResourcesTest, opened App.xaml and changed the Application.Resources
section to the following:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WP7ExternalResourcesTestLibrary;component/External.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Foreground="{StaticResource ForegroundBrush}"
添加到名为PageTitle"的 TextBlock
.TextBlock
正确地将页面名称"字样显示为红色.
Foreground="{StaticResource ForegroundBrush}"
to the TextBlock
named "PageTitle".TextBlock
correctly displayed the words "page name" in red.希望这会有所帮助.
这篇关于在 WindowsPhone 7 应用中使用外部 ResourceDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!