我试图在外部DLL中创建一个ResourceFile调用的DataTemplate.xaml,并在WP7页面中使用它.当我在我的页面的标题中执行以下操作时,我得到一个错误
< ResourceDictionary Source =“pack:// application:,/ WP7SharedClassLibrary; component / DataTemplate.xaml”/>
错误是
“当前项目不支持”应用程序“作为包URI的权限组件.”
有没有人遇到这个解决这个问题?
我已经设法使这个工作使用以下步骤:
>使用名为“WP7ExternalResourcesTest”的“Windows Phone应用程序”应用程序模板创建标准的WP7应用程序.
>使用名为“WP7ExternalResourcesTestLibrary”的“Windows Phone Class Library”模板将项目添加到同一个解决方案.
>从库项目中删除默认的Class.cs文件.
>使用“XML文件”模板添加一个名为“External.xaml”的文件,并将“Build Action”设置为“Page”.
>将新的XAML添加到新的XAML文件中:
<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部分更改为以下内容:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WP7ExternalResourcesTestLibrary;component/External.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
>在MainPage.xaml中,将Foreground =“{StaticResource ForegroundBrush}”添加到名为“PageTitle”的TextBlock中.
在模拟器中运行应用程序.最终的结果是TextBlock正确地将红色的“page name”显示出来.
希望这可以帮助.