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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:56:33+00:00 2026-05-11T15:56:33+00:00

[Edit: Rethinking architecture along mvvm lines made this problem largely fall away – thanks

  • 0

[Edit: Rethinking architecture along mvvm lines made this problem largely fall away – thanks @kent]

Using Spring.NET + WPF.

Load two WPF buttons in the config:

<object name='Button1' type='System.Windows.Controls.Button, PresentationFramework' >   <property name='Name' value='Next' />   <property name='Width' value='200'/>   <property name='Content' value='Next'/> </object> <object name='Button2' type='System.Windows.Controls.Button, PresentationFramework' >   <property name='Name' value='Back' />   <property name='Width' value='200'/>   <property name='Content' value='Back'/> </object>    

and pass them into the constructor of a xaml class (‘code behind’)

<object name='MyNewScreen' type='MyControls.MyUserControl>   <constructor-arg name='buttons'>  <list>     <ref object='Button1'/>     <ref object='Button2'/>   </list>  </object> 

where the class constructor has:

public DataGridControl(ArrayList buttons) {     //(yes this should be a List<Button> but I can't make spring happy with that)     foreach(var b in buttons) this.stackPanel.Children.Add(b);     ... 

Throws a:

Specified Visual is already a child of another Visual or the root of a CompositionTarget.

Now, I see the .GetHashCode() is the same for both buttons coming from Spring. So I can understand what WPF doesn’t like.

But I can’t do a XamlReader.Load(new XmlNodeReader(document)); as some have suggested, without losing my event wiring.

Any ideas how to get around this?

[Edit] I am wiring up events. Event wiring is not a problem, but it does explain why I’d want to do this in the first place. I’d left this out of the original post for the sake of brevity:

<object id='eventListener2' type='MyEventListener'> <listener event='Click' method='b_Click'> <ref object='Button2' /> </listener> </object> 
  • 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. 2026-05-11T15:56:34+00:00Added an answer on May 11, 2026 at 3:56 pm

    Having the same hash code does not mean the object instances are the same. An easy way to check whether they are actually the same instance is to set a breakpoint in your constructor and evaluate this expression in the watch window:

    object.ReferenceEquals(buttons[0], buttons[1]) 

    If true, they are exactly the same object and that is your problem.

    That said, I think it far more likely that you are creating multiple controls, each of which imports the same Buttons through Spring configuration.

    As per the Spring documentation, the default scope for an object is singleton. What you really want is for Spring to create a new instance of the Button for each control that needs it. Therefore, your configuration should look more like this:

    <object name='Button1' type='System.Windows.Controls.Button, PresentationFramework' singleton='false'>   <property name='Name' value='Next' />   <property name='Width' value='200'/>   <property name='Content' value='Next'/> </object> 

    And having said all that, I think you’d be far better off using an MVVM approach. You could have Spring provide the view model instances (which can be shared without issue) and generate the UI off that model.

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

Sidebar

Ask A Question

Stats

  • Questions 231k
  • Answers 231k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use the following function like this: Image('/path/to/original.image', '1/1', '150*', './thumb.jpg');… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer Check you database schema to see if the field (referenced… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer I figured out the problem - there was a session… May 13, 2026 at 2:13 am

Related Questions

[Edit: Rethinking architecture along mvvm lines made this problem largely fall away - thanks
My goal is to install only one WAR file but to use test or
I have heard that closures could be introduced in the next Java standard that
I've read the SVN red-bean book, and research how people layout their SVN repos,
Background We need to develop a specialised CMS (internal use only) to support a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.