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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:04:31+00:00 2026-06-06T07:04:31+00:00

I have a WPF Panel (like Canvas for example) and I want to remove

  • 0

I have a WPF Panel (like Canvas for example) and I want to remove its Children only if these children are of type T, for example all of type Button.

How can I do this? Can I use LINQ?

  • 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-06-06T07:04:33+00:00Added an answer on June 6, 2026 at 7:04 am

    You can use LINQ, this is one way of doing.

    canvas1.Children.OfType<Button>().ToList().ForEach(b => canvas1.Children.Remove(b));
    

    OR you can loop though all the Child elements and if it is button add them to a list and finally remove them. don’t remove buttons inside foreach loop.

    List<Button> toRemove = new List<Button>();
    foreach (var o in canvas1.Children)
    {
        if (o is Button)
            toRemove.Add((Button)o);
    }
    for (int i = 0; i < toRemove.Count; i++)
    {
        canvas1.Children.Remove(toRemove[i]);
    }
    

    LINQ way is more readable and simple and less coding.

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

Sidebar

Related Questions

I would like use a panel whose children have coordinates specified as percentage of
I have wpf Expander control and I want change background color of Header when
I have a WPF ItemsControl with a Canvas ItemPanel. Drawing from an internal source,
I have two pages in WPF. Page A contains all of my code. Page
I have a WPF window with expandable panel (via Expander ). The panel is
I've only been working with WPF for a few months, but I have an
I am developing an e-commerce administration panel in WPF. I would like to display
I am developing an e-commerce administration panel in WPF. I would like to display
I have a navigation panel in the left hand side of my WPF application.
I have a canvas (Panel Control) in my WinForms app where users can drag

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.