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

  • Home
  • SEARCH
  • 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

Related Questions

EDIT: upgraded this question to MVC 2.0 With asp.net MVC 2.0 is there an
Edit: Just wanted to make the question I have more clear. I pretty much
EDIT: please read the question and why I want to do it before passing
Edit : Note that my final purpose here is not having the class working,
We are currently running rails 2.1. My main motivation for the upgrade is the
i wish to create a repository pattern but with a WCF Rest Service which
We're thinking about switching technology for our future projects going from C++ to Java
I'm designing a C# application Presentation ( web site + flex apps ) Business
Greetings everyone, A friend and I are discussing the possibility of a new project:
I recently (after hours of debugging) tracked down a segfault in an Objective-C iPad

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.