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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:52:25+00:00 2026-05-15T12:52:25+00:00

I think this is my overall .NET inexperience speaking here, but I cannot figure

  • 0

I think this is my overall .NET inexperience speaking here, but I cannot figure out why this is happening to me.

My Model ImportManys an interface called ISystemSetupEditor, and in this case I have a couple of parts that Export that interface.

In the application’s ViewModel, I have a method that creates a menu, and iterates over the IEnumerable<ISystemSetupEditor> to populate the menu items, like so:

private ObservableCollection<WPFMenuItem> CreateSystemSetupItems()
{
    ObservableCollection<WPFMenuItem> menu = new ObservableCollection<WPFMenuItem>();

    foreach(ISystemSetupEditor editor in _model.SystemSetupEditors) {
        WPFMenuItem menuitem = new WPFMenuItem( editor.GetName());
        menuitem.Command = new RelayCommand( () => editor.ShowTool());
        menu.Add( menuitem);
    }

    return menu;
}

The problem is, when I click on any menu item, the ShowTool() for the last-enumerated ISystemSetupEditor-derived object always gets called. It’s as if the same reference is being stored by each RelayCommand.

I was hoping that someone could:

  • explain why this is happening, or at least give me a keyword so I can look it up and figure it out on my own
  • present possible solutions — the only one I’ve come up with so far is to manage a separate Dictionary, where T,U would be able to resolve to the correct library so the right function can get called later on.
  • 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-15T12:52:26+00:00Added an answer on May 15, 2026 at 12:52 pm

    Thats basically how closures and loops work in c#.

    Take a look at good explanation here

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

Sidebar

Related Questions

I cant figure out the syntax for this iv browsed the net when i
I think this could be a very easy question for you. But I have
(I think this is a pretty basic question on OOP, but unfortunately I wasn't
I think this is a pretty straightforward problem but... var outerHeight = $('.profile').outerHeight(); $(#total-height).text(outerHeight
I think this is mostly because I'm new to PHP OOP, but I have
I think this question has been asked many a times but I've been searching
I think this is an overly easy question but my brain is failing to
I may have the wrong pattern here, but I think it's a fair topic.
I think this is easily explained by looking at code, so I'm posting a
I think this is a simple and a silly question. I have included a

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.