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 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

This is in regards to a situation where Session is used to store some
In regards to this: http://stackoverflow.uservoice.com/pages/general/suggestions/103227-parser-does-not-match-all-valid-urls is this regex adequate or will it need to
I'm pretty sure this is a simple question in regards to formatting but here's
What things do I need to consider when doing this: What to remove/manipulate/add Regards
I have followed this tutorial which allowed me to create a Silverlight DataGrid that
HI there, So I followed this tutorial: http://www.tc.umn.edu/~brams006/selfsign_ubuntu.html step by step in installing a
I'm trying to add a Search bar to my UITableView. I followed this tutorial:
I've used a tutorial ( http://support.microsoft.com/kb/317535 ) to create a VB.NET Class that exports
I am new to Ajax and have been following a tutorial from JQuery.com. I
I suppose this question could just as easily be applied to PHP with regard

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.