简体   繁体   中英

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#? 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:

<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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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