简体   繁体   English

如何使用C#将WPF用户控件库添加到WPF窗口

[英]How do I add a WPF User Control Library using C# to a WPF window

I have 我有

xmlns:TechLog="clr-namespace:TechLog;assembly=TechLog"

And

                <TabItem Header="Technician">
                <TabControl>

                    <TabItem Header="System log">
                        <TechLog:UserControl1></TechLog:UserControl1>
                    </TabItem>

How do I do this in the .cs file of the WPF instead using C#? 我该如何在WPF的.cs文件中而不是使用C#? I want to do it dynamically so I add them on the fly 我想动态地进行操作,所以我可以即时添加它们

using TechLog;

 ...

UserControl ctrl = new UserControl();
this.TabItem1.Content = UserControl;

Add a name to the TabControl: 为TabControl添加一个名称:

<TabItem Header="Technician">
   <TabControl x:Name="tabCtrl" />
</TabItem>

In code file: 在代码文件中:

Add using: 使用添加:

using TechLog;

Add tab: 添加标签:

   string header = "My tab header";
   var newTab = new TabItem() { Header = header };
   tabCtrl.Items.Add(newTab);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM