Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3760480
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:28:41+00:00 2026-05-19T10:28:41+00:00

I have a TabControl control <TabControl Name=Farms_myVillages ItemsSource={Binding Villages}> </TabControl/> In the code behind

  • 0

I have a TabControl control

<TabControl Name="Farms_myVillages"
            ItemsSource="{Binding Villages}">
</TabControl/>

In the code behind I add some tabs dynamically to the TabControl as follows:

foreach (Village vill in Villages)
{
    TabItem tab = new TabItem();
    tab.Header = vill.Name;
    VillageUserControl c = new VillageUserControl();
    c.DataContext = vill;
    tab.Content = c;
    Farms_myVillages.Items.Add(tab);
}

where VillageUserControl is a UserControl that deal with the specified village. This code works fine and it gets the expected results…

The problem is that I don’t want this to be in the code behind but just in the xaml itself.

I try this:

<TabControl Name="Farms_myVillages"
            ItemsSource="{Binding Villages}">
      <TabControl.ItemContainerStyle>
          <Style TargetType="TabItem">
              <Setter Property="Header" Value="{Binding Name}"/>
              <Setter Property="Content">
                 <Setter.Value>
                    <u:VillageUserControl DataContext="{Binding}"/>
                 </Setter.Value>
              </Setter>
          </Style>
      </TabControl.ItemContainerStyle>
</TabControl>

After I run it, it throws an exception: “Specified element is already the logical child of another element. Disconnect it first.”

Did I miss something? Please help me here…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T10:28:41+00:00Added an answer on May 19, 2026 at 10:28 am

    You set the wrong thing, you should not modify the ItemContainerStyle but the TabControl.ItemTemplate for the header and TabControl.ContentTemplate for the content.

    (The exception may have to do with the fact that in the style only one VillageUserControl is created, but the style applies to multiple tab items.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data bound tab control: <TabControl ItemsSource={Binding Products} Name=ProductsTabControl> <TabControl.ItemTemplate> <DataTemplate> <TextBlock
I have a tab control: <TabControl IsSynchronizedWithCurrentItem=True ItemsSource={Binding} ItemTemplate={StaticResource ClosableTabItemTemplate} > </TabControl> I want
I have a tab control bound to an observablecollection for dynamic tabs as follows:
I have the following TabControl: <TabControl x:Name=Networks> <TabControl.ItemTemplate> <DataTemplate> <StackPanel Orientation=Horizontal> <TextBlock Text={Binding DisplayName}
I have a form where I can add tabs into a tabcontrol by pressing
I have a tabControl control with multiple tabs. For each tab, I am adding
I'm trying to enable tabs functionality in the WebBrowser control. I have a TabControl
Problem I have a custom tab control using Chrome-shaped tabs that binds to a
I have a tab control on a form, and a couple different tabs have
Background: I'm trying to implement a tab control. The tabs are as follows: |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.