开发者

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 ma开发者_StackOverflow社区naged 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/


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>


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜