user665808
user665808

Reputation: 11

how to dynamically add content to tab in wpf

I'm new to wpf and c# programming. What i need to do, is to be able to create a tabControl dynamically in runtime with data imported from xml files. So far i have managed to read the data from the xml files and dynamically create the tabs' headers (but not add the thumbnail in the tab header)... but i can't figure out how to load the data into tabs... I want to do something like the screen shot below... The data loaded into the tabs need to be images along with a tool-tip if possible! It has to be done in run-time, since the tabs and the data into each tab may change..

anyone has any idea how to achieve this?

Thanks!

PS> screen-shot: http://img703.imageshack.us/i/screendn.png/

Upvotes: 1

Views: 2126

Answers (2)

Code0987
Code0987

Reputation: 2618

You can put any control in header of tabitem. TabItem header value is type of object.

Ex:

Dim tabitem As TabItem
tabitem.Header = New Button With {.Content = "Button"}
tabcontrol.Items.Add(tabitem)

Upvotes: 0

Arsen Mkrtchyan
Arsen Mkrtchyan

Reputation: 50752

You can read data from xml file to List collection and bind TabControl to it, like this

 <TabControl x:Name="TheTabControl" ItemsSource="{Binding XmlData}">
        <TabControl.ItemTemplate>
            <DataTemplate>
                <TabItem Header="{Binding XmlHeader}">
                    <StackPanel Margin="10" Orientation="Horizontal">
                        <TextBlock Text="{Binding xmlContent}"/>
                    </StackPanel>
                </TabItem>
            </DataTemplate>                
        </TabControl.ItemTemplate>
    </TabControl>

Upvotes: 2

Related Questions