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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:02:13+00:00 2026-05-23T02:02:13+00:00

My question is based on an example from WPF, but, I think, it’s more

  • 0

My question is based on an example from WPF, but, I think, it’s more about C# in general.

Suppose I have a WPF app where I use several types of Custom Controls, let it be CustControl1, CustControl2, CustControl3. The page can dynamically load the XAML with controls of either of the types.
This very page has a code-behind where some manipulations are made with the Custom Controls, like:

List<CustControl1> MyCustControls = this.Descendents().OfType<CustControl1>().ToList();          
foreach (CustControl1 cntr in MyCustControls)
{
   ...

In the above code the CustControl1 type is explicitly defined, and if other types of Custom Controls are loaded on the page (of CustControl2 or CustControl3 type), the code will not recognize it.

My level of C# knowledge is insufficient to find out how to solve such a problem of multiple type recognizing. Or is it possible in C# at all?

  • 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-23T02:02:14+00:00Added an answer on May 23, 2026 at 2:02 am

    If I understand your question correctly, this is a basic OOP concept.

    You would pass in all of your controls as their parent class (UserControl, or even Control), or an interface they all implement (IControl for example)

    then, if the method you are trying to call exists in the parent, you can just call it:

    List<UserControl> MyCustControls = this.Descendents().OfType<UserControl>().ToList();          
    foreach (UserControl cntr in MyCustControls)
    {
       cntr.SomeShareMethod()
    

    or, if you need to call it explicitly on concrete implementation, you can do this:

    List<Control> MyCustControls = this.Descendents().OfType<Control>().ToList();          
    foreach (Control cntr in MyCustControls)
    {
       if (cntr is CustControl1) 
           ((CustControl1)cntr).SomeSpecificMethod()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to use Sync Framework 2.0 in our WPF app that will contain
This is based on the example from the book: Pro WPF and Silverlight MVVM
This is sort of SQL newbie question, I think, but here goes. I have
i have a question about event based program performance. in my company we have
Here's another C#/.NET question based merely on curiousity more than an immediate need ...
I have a linq query which returns the ID of a question based on
Ok this is more of a computer science question, than a question based on
This question is based on the thread . I have the shell function function
I think the title for this question is probably wrong, but I'm not sure
I have a question about a particular query I'd like to execute against 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.