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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:49:44+00:00 2026-05-20T14:49:44+00:00

Im a noob at silverlight and .net. Just started playing with them and I’ve

  • 0

Im a noob at silverlight and .net. Just started playing with them and I’ve got an event attached to a custom control that behaves strangely. This would be the handler code:

private void clickCloseWindow(object sender, RoutedEventArgs e)
    {
        StackPanel ctrl = (StackPanel)FindName("WindowsPanel");

        var s = from r in ctrl.Children.OfType<BarWindowTab>() where r.Id==Id select r;

        foreach (BarWindowTab b in s)
        {
            ctrl.Children.Remove(b);
        }

        parent.Children.Remove(this);
    }

As u can see, I’m trying to remove several objects from screen. The thing is, the handler exits after each removal for some reason instead of removing them all at once. When I press the button first time, it removes the stackpanel child, then it exits and I have to press it again to remove the other object. Anybody have an explanation why ?

  • 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-20T14:49:45+00:00Added an answer on May 20, 2026 at 2:49 pm

    Once you’ve got past the fact you’re only selecting one item with a matching ID, you’ll probably have another problem. I imagine if you attach a debugger and catch exceptions you’ll discover one will get thrown 🙂

    You’re modifying the collection ctrl.Children as you iterate through it, which breaks the whole enumeration pattern. (Remove one item -> try to move to next -> “oh pants, the collection has changed”)

    Linq queries generate what you can think of as a decorated enumerator, pointing to the original collection. Forcing s to be a seperate collection by calling ToList or ToArray will fix this.

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

Sidebar

Related Questions

I'm an absolute Silverlight noob that is confused by the help file. Here is
noob here i got this jquery code that i found on stackoverflow var maxLines
We have a Logitech web cam that we want to get working with .NET.
I've been developing a Silverlight-c# client-server game that has now gotten to the point
OK, total noob question here. I'm toying around with Silverlight, and need to connect
Noob here. I have a rails app that has users and postings. I need
Noob ADO.NET question: Can I do the following? Retrieve a DataTable somehow. Dispose it.
Noob here... :) I'm working on a small and personal project that is already
Noob question: I'm currently under the impression that when you want to create an
XSL noob here :-) I've got the following template which is being used to

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.