0

I have a TabControl with dynamically created tabs and content that vary depending on the XML that is passed in but, I also need a couple of TabItems to be created regardless of the XML content. When I add a <TabItem Header="Users"/> I receive a Items Collection must be empty before using an ItemsSource. Here is what I have now:

<TabControl ItemsSource="{Binding Content}">

                <TabControl.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="Header"/>
                    </DataTemplate>
                </TabControl.ItemTemplate>

                <TabControl.ContentTemplate>
                    <DataTemplate>
                        <TextBlock Text="Tab Content"/>
                    </DataTemplate>
                </TabControl.ContentTemplate>                   
            </TabControl>

Is there anyway to do this? Thanks!

codeBlue
  • 185
  • 1
  • 1
  • 11

2 Answers2

3

As indicated by the error, you must choose between either data binding the ItemsSource, or setting the Items property - you can't do both. You could use a CompositeCollection to combine the contents of the dynamic tabs with another collection containing the non-dynamic tabs. You can then bind the ItemsSource to this CompositeCollection.

Kent Boogaart
  • 175,602
  • 35
  • 392
  • 393
1

You can use the CompositeCollection to achieve the desired functionality. This might be helpful(though it talked TreeView here) - Binding to a single element inside a CompositeCollection

Community
  • 1
  • 1
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185