在 WindowsPhone 7 应用中使用外部 ResourceDictionary [英] Use an External ResourceDictionary in a WindowsPhone 7 app

查看:23
本文介绍了在 WindowsPhone 7 应用中使用外部 ResourceDictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在外部 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:

  1. 使用名为WP7ExternalResourcesTest"的Windows Phone 应用程序"应用程序模板创建了一个标准的 WP7 应用程序.
  2. 使用名为WP7ExternalResourcesTestLibrary"的Windows Phone 类库"模板向同一解决方案添加了一个项目.
  3. 从库项目中删除了默认的 Class.cs 文件.
  4. 使用XML 文件"模板添加了一个名为External.xaml"的文件,并将构建操作"设置为页面".
  5. 将以下 XAML 添加到新的 XAML 文件中:

  1. Created a standard WP7 application using the "Windows Phone Application" application template called "WP7ExternalResourcesTest".
  2. Added a project to the same solution using the "Windows Phone Class Library" template called "WP7ExternalResourcesTestLibrary".
  3. Removed the default Class.cs file form the library project.
  4. Added a file called "External.xaml" using the "XML file" template and set the "Build Action" to "Page".
  5. 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 项目中添加对它的引用.
  • 在 WP7ExternalResourcesTest 中,打开 App.xaml 并将 Application.Resources 部分更改为以下内容:

  • Built the library project, and then added a reference to it from the WP7ExternalResourcesTest project.
  • 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>
    

  • 在 MainPage.xaml 中,将 Foreground="{StaticResource ForegroundBrush}" 添加到名为PageTitle"的 TextBlock.
  • 在模拟器中运行应用程序.最终结果是 TextBlock 正确地将页面名称"字样显示为红色.
  • In MainPage.xaml, added Foreground="{StaticResource ForegroundBrush}" to the TextBlock named "PageTitle".
  • Ran the application in the emulator. The end result was that the TextBlock correctly displayed the words "page name" in red.
  • 希望这会有所帮助.

    这篇关于在 WindowsPhone 7 应用中使用外部 ResourceDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆