将第三方命名空间(嵌入式DLL的)命名空间导入XAML

时间:2014-07-10 19:47:30

标签: c# wpf xaml

我正在尝试导入嵌入到我的EXE的DLL的命名空间。 我正在为此应用程序使用WPFtoolkit,因此我的XAML正在访问命名空间,如下所示:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" x:Class="Imperium.MainWindow"
        Title="Imperium" Height="435" Width="510" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" Icon="pack://application:,,,/ExtFiles/Imp.ico" Closing="Window_Closing" MouseDown="Grid_MouseDown" WindowStyle="None" BorderThickness="1" BorderBrush="Black" Foreground="Black">

它可以在本地复制DLL时正常工作。但是我希望这两个DLL都嵌入到我的EXE中。两个DLL中的一个(WPFToolkit.dll)没有问题,因为它在XAML中没有引用,所以我使用的解决方案(参见http://codeblog.larsholm.net/2011/06/embed-dlls-easily-in-a-net-assembly/comment-page-1/#comment-818对此工作正常)。 / p>

但是,第二个dll(system.windows.controls.datavisualization.toolkit.dll)给了我麻烦。

任何想法我怎么能这样做?

谢谢你 史蒂夫

编辑:让我澄清一点:

我的应用程序有2个DLL,我能够将两者都嵌入到EXE中(文件大小显示在那里),其中一个被称为正常(仅使用&调用) #39; S)

另一个被称为XAML名称空间导入 - 当我运行程序时出现错误。

这是我的App.g.cs

public static void Main() {
            AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly; //aded
            Swiftech_Imperium.App app = new Swiftech_Imperium.App();
            app.InitializeComponent();
            app.Run();
        }

        // added
        private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args)
        {
            Assembly executingAssembly = Assembly.GetExecutingAssembly();
            AssemblyName assemblyName = new AssemblyName(args.Name);

            string path = assemblyName.Name + ".dll";
            if (assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false)
                path = String.Format(@"{0}\{1}", assemblyName.CultureInfo, path);
            using (Stream stream = executingAssembly.GetManifestResourceStream(path))
            {
                if (stream == null)
                    return null;
                byte[] assemblyRawBytes = new byte[stream.Length];
                stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length);
                return Assembly.Load(assemblyRawBytes);
            }
        }

查看XAML帖子的开头。

两个DLL都设置了对嵌入式资源的设置操作&#34;。

我使用了这个&#34;教程&#34;:http://www.digitallycreated.net/Blog/61/combining-multiple-assemblies-into-a-single-exe-for-a-wpf-application

我无法找到本教程中提到的XAML(目标)的位置,因此它可能无法正常工作。

我正在使用VS Express 2013,这可能就是为什么我无法找到作者所指的内容:

(this code snippet should be added to your project file underneath where the standard Microsoft.CSharp.targets file is imported):

1 个答案:

答案 0 :(得分:0)

我知道这是迟到的答案,但我自己也明白了。您需要使用外部文本编辑器实际打开项目文件,并粘贴链接教程中提供的内容。

这应该可以解决你的问题。