如何在运行时将wpf UserConrol项目插入MainWindow项目中(最后已解决:-) [英] How to insert wpf UserConrol projects into a MainWindow project at runtime (Finally was solved:-)

查看:113
本文介绍了如何在运行时将wpf UserConrol项目插入MainWindow项目中(最后已解决:-)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生

好的,我想通过在运行时中选择UserContols作为主机上的MainWindow项目上的DLL来加载任何UserContols.
我尝试了这篇文章 SelfContainedAssembly [我的项目 [ ^ ] ,也可以成功使用StackPanel等对其进行测试,但是我想开发这样的WPF UserControl项目

Hi sir

Ok, I want loading any UserContols as DLL on a MainWindow project as host by selecting them in runtime.
I tried this article SelfContainedAssembly[^] and I converted it to a WPF project that you can see MyProject[^], also test it with StackPanel and etc succesfully, but I want develope a WPF UserControl project like this

<usercontrol x:class="ManyWpfControlLibrary.UserControl1" xmlns:x="#unknown">
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="150" d:DesignWidth="300">
    <grid removed="#FFFA8383">

    </grid>
</usercontrol>



带有代码隐藏



with code-behind

namespace ManyWpfControlLibrary
{
    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }
    }
}



此UserControl编译为DLL文件,最后将在运行时插入到我的MainWindow项目中,但我无法执行此操作.

实际上,我们还不了解DLL(由UserControl编译),它是由另一个人离线创建和开发的,并且位于不同的程序集中,只有在运行时才将其加载并插入到主项目中!

帮助我了解这种方法或其他想法.如果问题含糊不清,并且您有主意,请编辑此帖子以进一步了解.

在此先感谢.



This UserControl compiled to a DLL file, finally it would insert into my MainWindow project at runtime, but I couldn''t to do this.

In fact, we haven''t aware about the DLL (UserControl compiled), it created and developed offline by another persons and there is on a different assembly, only we load and insert it on the main project at runtime!

Help me about this method or another idea. If the issue is ambiguous and you got the idea, please you edit this post to more understanding.

Thanks in advance.

推荐答案

类似这样的东西:

Something like this:

MyControl control = new MyControl();
this.rootGrid.Children.Add(control);


好,终于可以了!我的问题解决了:-)

1)打开ManyWpfControlLibrary.csproj的AssemblyInfo.cs文件.
2)在此文件中添加以下属性[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
3)构建该项目以获取具有该属性的新装配.
4)从这个新程序集中创建* .zip
5)从WpfUserControlFactory.csproj中删除较旧的DependancyAssemblies.zip
6)在步骤4中添加新创建的zip作为WpfUserControlFactory.csproj中的嵌入式资源.
Ok guys, finally! my problem was solved:-)

1) Open AssemblyInfo.cs file of ManyWpfControlLibrary.csproj .
2) Add following attribute to this file[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
3) Build this project to get new assembly with the attribute.
4) Create *.zip from this new assembly
5) Delete older DependancyAssemblies.zip from WpfUserControlFactory.csproj
6) Add newly created zip in step 4 as embedded resource in WpfUserControlFactory.csproj.


这篇关于如何在运行时将wpf UserConrol项目插入MainWindow项目中(最后已解决:-)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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