question

NicholasPiazza-0093 avatar image
0 Votes"
NicholasPiazza-0093 asked ·

How to append TabItem to TabControl in C# instead of XAML

I'm experimenting with WPF applications. Using the designer I created a TabControl with two TabItems that are set up in XAML. Then I wanted to see about creating a third TabItem in C# code and attaching it to the TabControl using code instead of XAML. Here is what I have so far.


However, at this point, I can't find any method or property in TabControl that lets me append the new TabItem. Is there a way to do this in C# code?

windows-wpf
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DaisyTian-MSFT avatar image
0 Votes"
DaisyTian-MSFT answered ·

Welcome to our Microsoft Q&A platform!
You can set your TabControl name as 'MyTabControl', then add the 'MyTabControl.Items.Add(Converters); ' in C# code.
Step1:

 <TabControl Name="MyTabControl">

Step2:

 TabItem Converters = new TabItem();
             Converters.Header = "Unit converters";
             Converters.Background = Brushes.Transparent;
             MyTabControl.Items.Add(Converters);

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NicholasPiazza-0093 avatar image
0 Votes"
NicholasPiazza-0093 answered ·

8758-tabitem.png


Forgot to attach this image in previous post. Didn't see a way to edit the post.


tabitem.png (25.9 KiB)
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.