我正在尝试在外部 dll 中创建一个名为 DataTemplate.xaml 的 ResourceFile 并在 WP7 页面中使用它。当我在页面标题中执行以下操作时,出现错误
<ResourceDictionary Source="pack://application:,,,/WP7SharedClassLibrary;component/DataTemplate.xaml" />
错误是“当前项目不支持‘应用程序’作为包 URI 的权限组件。”
有没有其他人遇到过这个并解决了这个问题?
我正在尝试在外部 dll 中创建一个名为 DataTemplate.xaml 的 ResourceFile 并在 WP7 页面中使用它。当我在页面标题中执行以下操作时,出现错误
<ResourceDictionary Source="pack://application:,,,/WP7SharedClassLibrary;component/DataTemplate.xaml" />
错误是“当前项目不支持‘应用程序’作为包 URI 的权限组件。”
有没有其他人遇到过这个并解决了这个问题?
我已经设法使用以下步骤使其工作:
将以下 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 中,打开 App.xaml 并将Application.Resources部分更改为以下内容:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WP7ExternalResourcesTestLibrary;component/External.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Foreground="{StaticResource ForegroundBrush}"了TextBlock名为“PageTitle”。TextBlock正确地以红色显示“页面名称”。希望这可以帮助。
我在尝试共享 XAML ResourceDictionary 文件时尝试了 pack 语法并得到了相同的错误消息。我最终使用了这种语法,它对我有用。
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyDLLName;component/Folder/MyXAMLFile.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Silverlight 不支持包 URI。这是 WPF 的一项功能。
如果您在 Silverlight 中检查对象的Source属性类型,它是. 但在 WPF 中,源是一个依赖属性,类型为ImageUriImageSource.