简体   繁体   中英

How do I dynamically add an XAML file in a TabItem

I'm learning to use WPF in C# to make an application, basically I have a TabControl and a single TabItem called "Home" , inside this "Home" tab is a button called "New" and when a user clicks the button I want to add a TabItem to the TabControl from an XAML file, below is the TabItem in the XAML file, how do I go about doing this? any help is greatly appreciated

<TabItem Header="New">
    <StackPanel>
        <TextBlock Text="Hello New Tab!"/>
    </StackPanel>
</TabItem>

Edit: There are around 15 different button in which all have different designs in different XAML files, above is only just an example since they are too big to add them here

You need to do this in code behind. Here's an example how to do this: https://stackoverflow.com/a/6759283/1252575

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