Reputation: 195
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!
Upvotes: 0
Views: 2284
Reputation: 178630
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
.
Upvotes: 3
Reputation: 81233
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
Upvotes: 1