【发布时间】:2012-04-03 21:42:12
【问题描述】:
我有一个 WPF 应用程序,我正在尝试将其转换为 DLL。问题是我在 App.XAML 中设置了许多应用程序级资源。在 dll 中,我试图以编程方式设置我的资源。
要以编程方式加载我的资源,我有这个:
ResourceDictionary myResourceDictionary = new ResourceDictionary();
myResourceDictionary.Source = new Uri("C:\\Users\\Ash\\Documents\\Visual Studio 2010\\Projects\\moo Process Flow Manager\\moo Process Flow Manager\\Resources\\Styles\\Shared.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary = new ResourceDictionary();
myResourceDictionary.Source = new Uri("C:\\Users\\Ash\\Documents\\Visual Studio 2010\\Projects\\moo Process Flow Manager\\moo Process Flow Manager\\Resources\\Styles\\ToolBar.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary = new ResourceDictionary();
myResourceDictionary.Source = new Uri("C:\\Users\\Ash\\Documents\\Visual Studio 2010\\Projects\\moo Process Flow Manager\\moo Process Flow Manager\\Resources\\Styles\\ZoomBox.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
这一行:
myResourceDictionary.Source = new Uri("C:\\Users\\Ash\\Documents\\Visual Studio 2010\\Projects\\moo Process Flow Manager\\moo Process Flow Manager\\Resources\\Styles\\ZoomBox.xaml");
在运行时抛出以下错误:
'Failed to create a 'Type' from the text 's:ZoomBox'.' Line number '5' and line position '12'.
内部例外:
{"Type reference cannot find type named '{clr-namespace:Arkitec.moo.ProcessFlowManager.Controls}ZoomBox'."}
这是导致 zoombox.xaml 中错误的行:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:Arkitec.moo.ProcessFlowManager.Controls">
<Style TargetType="{x:Type s:ZoomBox}">
这是在 zoombox.cs 中声明该类的位置:
namespace Arkitec.moo.ProcessFlowManager.Controls
{
public class ZoomBox : Control
{
如果您需要更多信息,请告诉我。
编辑:根据我试过的 Guilammes 回答:
myResourceDictionary.Source = new Uri("Resources/Styles/Shared.xaml", UriKind.Relative);
但是得到以下错误:
Cannot locate resource 'resources/styles/shared.xaml'.
【问题讨论】:
-
我删除了我的答案,因为你编辑了你的问题。我希望有人能帮助你更多
标签: c# wpf xaml namespaces