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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:28:51+00:00 2026-05-19T16:28:51+00:00

Sorry about the stupid title, had no idea how to word this I’m creating

  • 0

Sorry about the stupid title, had no idea how to word this

I’m creating a class that has two lists of the same type. It’s used to copy a reference to a object in the first list to the second list.

While both lists will be of the same type (hold the same type of object) it can be different each time this class is initialized.

So I’m guessing I should make the List types as some kind of abstract list. I would like to ensure they will be strongly typed when instanced (but not neccesary if problematic). The problem is inside the method that moves selected items from list1 to list2 abstract list types normally don’t have methods for that.

I guess the normal solution would be to make the class generic ( className<T> thingy ) but I’m not sure I can do that ( at least I don’t know how ) because this class inherits a WPF UserControl.

Here is the Code:

public partial class SubsetSelectionLists : UserControl
{
    public static DependencyProperty SetCollectionProperty = DependencyProperty.Register("SetCollection", typeof("Need a abstract list type here"), typeof(SubsetSelectionLists));
    public static DependencyProperty SubsetCollectionProperty = DependencyProperty.Register("SubsetCollection", typeof("Need a abstract list type here"), typeof(SubsetSelectionLists));

    public "Need a abstract list type here" SetCollection
    {
        get
        {
            return ("Need a abstract list type here") GetValue(SetCollectionProperty);
        }
        set
        {
            SetValue(SetCollectionProperty, value);
        }
    }

    public "Need a abstract list type here" SubsetCollection
    {
        get
        {
            return ("Need a abstract list type here")GetValue(SubsetCollectionProperty);
        }
        set
        {
            SetValue(SubsetCollectionProperty, value);
        }
    }

    public SubsetSelectionLists()
    {
        InitializeComponent();
        SubsetSelectiongrid.DataContext = this;
    }

    private void selectionBtnClick(object sender, RoutedEventArgs e)
    {
        SubsetCollection.AddTheseItems(SET.SelecctedItems)
    }

    private void removeBtnClick(object sender, RoutedEventArgs e)
    {
        SUBSET.RemoveTheseItems(SUBSET.SelectedItem);
    }
}

EDIT: Solution

Some answers pointed me towards the optimal solution of creating a Generic Class. However this can be problematic in WPF. You would have to skip the XAML on the top level generic class.

This would mean that you could do the XAML in the type specific child classes which isn’t something you would like to do (unless only the code is something you would re-use but the look is variable). You could also have designed the control using code I guess but I’m not sure how effective that would be.

I was pointed towards the IList object which is a abstract list that many others inherit from and I’m gonna use. It’s a bit of a hack but as this will not be used in a open library I’m ok with it. Otherwise I would use the Generic Route.

  • 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-19T16:28:51+00:00Added an answer on May 19, 2026 at 4:28 pm

    I don’t know how well the designers play with user controls that are generic classes. If that is a problem (which I would guess), one way to get away from that is to expose the collections IList but still use List<T> that are constructed in runtime to have type safety in the storage (code sample reduced to include only list object creation and properties for exposing them; add code for DependencyProperty and so on as needed):

    public class YourControl : UserControl
    {
    
        // this method will set up the internal lists for accepting
        // objects of the specified type only
        public void SetListType(Type containedType)
        {
            var listType = typeof(List<>).MakeGenericType(new[] { containedType });
            SetCollection = (IList)Activator.CreateInstance(listType);
            SubsetCollection = (IList)Activator.CreateInstance(listType);
        }
        public IList SetCollection { get; private set; }
        public IList SubsetCollection { get; private set; }
    }
    
    // usage example:
    theControl.SetListType(typeof(string));
    theControl.SetCollection.Add("some string"); // works ok
    theControl.SetCollection.Add(42); // fails, 42 is not a string
    

    The obvious downside is that SetCollection and SubsetCollection expose “untyped” object lists.

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

Sidebar

Related Questions

Sorry if this is a stupid question, but it's something that I'm curious about.
I have a question about regex/Python. Sorry if this topic has been discussed millions
I´m sorry about my stupid question, but I´m stuck. I´m creating application, which will
Sorry about the title, I'm not exactly sure how to explain this with a
sorry for stupid question. But really interesting and incomprehensible. In this session discussed about
sorry for the stupid questions but there are just some things about WCF I
Sorry about a vague title, but here's what i am trying to do. I
Sorry about the title, I couldn't think of a better way to describe the
Sorry about the extremely vague question title (any suggestions for improvements welcome) I have
Sorry about the wording for my question title. I have a basic HTML anchor

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.