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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:50:41+00:00 2026-05-17T01:50:41+00:00

this is in regards to the tutorial on msdn . This is whats used

  • 0

this is in regards to the tutorial on msdn. This is whats used to close workspaces or tabs.

// workspaces declared as follows
_workspaces = new ObservableCollection<WorkspaceViewModel>();
_workspaces.CollectionChanged += this.OnWorkspacesChanged;

void OnWorkspacesChanged(object sender, NotifyCollectionChangedEventArgs e)
{
    if (e.NewItems != null && e.NewItems.Count != 0)
        foreach (WorkspaceViewModel workspace in e.NewItems)
            workspace.RequestClose += this.OnWorkspaceRequestClose;

    if (e.OldItems != null && e.OldItems.Count != 0)
        foreach (WorkspaceViewModel workspace in e.OldItems)
            workspace.RequestClose -= this.OnWorkspaceRequestClose;
}

What i don’t understand is what will e.NewItems and e.OldItems be. Assuming NewItems will be the new item thats added into the collection, I attach the event handler? But then it will be singular, since I add 1 item at a time usually? then if it means all the items that will still exists after the change, why will I need to re-attach the event handlers?

  • 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-17T01:50:42+00:00Added an answer on May 17, 2026 at 1:50 am

    The method is for handling a NotifyCollectionChanged event – it can be for an ‘Add’, ‘Move’, ‘Remove’, ‘Replace’ or ‘Reset’ action. ie items are being added or removed (etc) to/from the collection.

    • NewItems is the list of the new items invoved in the change.
    • OldItems is the list of items affected by a Replace, Remove, or Move action.

    So in other words, when you add a ViewModel into the collection, the ‘OnWorkspaceRequestClose‘ handler gets attached to the ‘RequestClose’ event of just that new ViewModel.

    If you add another ViewModel(s), then the handler gets attached to the new one(s), but the existing items in the collection won’t be affected…

    Incidentally, the second half of the method is removing the OnWorkspaceRequestClose event handlers for those ViewModels being closed (to prevent memory leaks)

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

Sidebar

Related Questions

Currently following the HelloWorld Tutorial on the monotouch website . I add the following
I was following a tutorial today that had me scratching my head for an
Hi Im trying to develop a oop php driven blog. Im new to the
A recent thread on SO triggerred this. An unnamed namespace is considered to be
Having little experience in Opengl es (or opengl) I was hoping somebody could help
I currently have a network camera that streams video as a .swf (and also
I am wondering how I can send data between a machine and a mobile
I'm developing a system with codeigniter, php and jquery these days, still in the
When upgrading from libxml2 2.6 to 2.7, some behavior changed for me. I've located

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.