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 8449041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:35:34+00:00 2026-06-10T10:35:34+00:00

I have recently started getting the exception Specified element is already the logical child

  • 0

I have recently started getting the exception “Specified element is already the logical child of another element. Disconnect it first." after converting a bunch of Frame controls to simpler ContentControl controls to host sub-model views within their logical parent model views.

In the below example, the commented out code when commented out will stop the crash from occurring:

<UserControl x:Class="GUI.Views.Scenario.PathogenRiskLiquidIngestionView"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:ScenModels="clr-namespace:GUI.ViewModels.ScenarioModels">

    <StackPanel Orientation="Vertical">
        <StackPanel Orientation="Vertical">
            <DockPanel>
                <Label DockPanel.Dock="Left" Content="Risk Assessment Title"></Label>
                <TextBox DockPanel.Dock="Right" Text="{Binding RiskAssessmentTitle, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"></TextBox>
            </DockPanel>
            <DockPanel>
                <Label DockPanel.Dock="Left" Content="Risk Calculated"></Label>
                <ComboBox SelectedItem="{Binding RiskCalculated, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding RiskCalculatedOptions}"></ComboBox>
            </DockPanel>
            <DockPanel>
                <Label DockPanel.Dock="Left" Content="{Binding MinAcceptableInfectionRiskLabel}"></Label>
                <TextBox DockPanel.Dock="Right" Text="{Binding MinAcceptableInfectionRisk, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"></TextBox>
            </DockPanel>
        </StackPanel>
        <!--<GroupBox Header="Pathogens">
            <StackPanel Orientation="Vertical">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                    <Button Content="Add Pathogen" Command="{Binding AddPathogen}"></Button>
                    <Button Content="Remove Pathogen" Command="{Binding RemovePathogen}" CommandParameter="{Binding SelectedIndex, ElementName=PathogenList}"></Button>
                </StackPanel>
                <ListView Name="PathogenList" ItemsSource="{Binding PathogensPresentViews}" Tag="{Binding}" BorderThickness="0" Background="Transparent">
                    <ListView.ItemTemplate>
                        <DataTemplate DataType="{x:Type ScenModels:PathogenPresentIngestViewModel}">
                            <ContentControl Content="{Binding}"></ContentControl>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackPanel>
        </GroupBox>
        <GroupBox Header="Receptor Characteristics">
            <StackPanel Orientation="Vertical">
                <ContentControl Content="{Binding ReceptorVolumeLiquidIngestedPerEventView}"></ContentControl>
                <ContentControl Content="{Binding ExposuresView}"></ContentControl>
            </StackPanel>
        </GroupBox>-->
    </StackPanel>
</UserControl>

After doing a search for this kind of exception the most common cause seems to be some incorrect styling, however in this application I have not yet styled any elements. Can someone please tell me what is likely to be causing this exception?

Thanks,
Alex.

  • 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-06-10T10:35:36+00:00Added an answer on June 10, 2026 at 10:35 am

    Without more knowledge of what all the underlying objects are i can not do much more than guessing…

    Here is something really fishy:

    <ListView Name="PathogenList" ItemsSource="{Binding PathogensPresentViews}" Tag="{Binding}" BorderThickness="0" Background="Transparent">
        <ListView.ItemTemplate>
            <DataTemplate DataType="{x:Type ScenModels:PathogenPresentIngestViewModel}">
                <ContentControl Content="{Binding}"></ContentControl>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
    

    As mentioned in the comments you should never even have a situation where you bind to *Views, the view model should not have references to views, but only view models. There is little point in following a model-view-separation pattern if you violate it like that.

    Anyway, as you bind to what presumably are views and hence UI-elements something undesirable might be happening here:

    1. DataTemplate is created: View is added to ContentControl -> Now a child of a control
    2. ListView goes “Well screw the DataTemplate, i can display this item as is.” (Because it is a view, which it should not be).
    3. ListView adds item (the view, which is the child of the ContentControl) to the ItemsPanel.
    4. Whoops!

    But that is probably not it, WPF should be smarter than that, so how about this: Multiple references to the same instance in the PathogensPresentViews list?

    Or the same view model is used in two places, creating two views, which both try to display the same list of UI-elements?

    Whatever the actual case may be, you should not fight the symptoms but the illness, which most likely is that your view models contain views.

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

Sidebar

Related Questions

I have a client website where I recently started getting compilation errors: CS0029: Cannot
I have recently started using R and am still getting used to its data
I have recently started looking into using Azure but I'm having some issues getting
I have recently started getting this error while posting to facebook newsfeed stream of
I am just getting started with Silverlight and have recently added a Silverlight project
I'm getting started with Rails (3.2.3), and have recently discovered the rake notes feature.
Recently I have started getting mySQL too many connection errors at times of high
I have recently started using Netbeans with following stack Liferay, icefaces with jBoss. Is
I have recently started to use Twitter Bootstrap and trying to understand how it
I have recently started learning c# and have come across an issue. I'm not

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.