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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:40:05+00:00 2026-05-18T12:40:05+00:00

I currently have a couple different user controls that provide the same functionality: three

  • 0

I currently have a couple different user controls that provide the same functionality: three different buttons called Select All, Deselect All, and Toggle Selected. These perform actions on a list of items that implement my ICheckable interface in each user control. I wanted to unify this stuff so that the commands and buttons would all be defined in one place only–a new user control–instead of being duplicated in two different user controls. My problem is that in one user control I’m dealing with a list of my Template class, and the other user control has a list of a Defect class. Both Template and Defect implement ICheckable, meaning the Select All, Deselect All, and Toggle Selected apply to them.

I have a generic container class SelectableItems<T> that requires T fit these constraints: where T : ICheckable, IEquatable<T>, IDeepCloneable<T>. SelectableItems<T> provides an ObservableCollection<T> Items property, along with other useful properties such as bool IsAnyItemSelected, T SelectedItem, etc. These properties would be used in implementing the Select All, etc. commands. Both Template and Defect fit all those constraints. I was going to create a dependency property in my new user control to which I would bind a SelectableItems<Template> and SelectableItems<Defect> property from my other user controls. I don’t think it’s possible to do a generic dependency property, though, because I can’t have a generic UserControl class since I’m using XAML. How should I go about this? I’m using .NET 3.5.

To sum up, this is what I want:

TemplateList user control                             ItemSelection user control
-------------------------------------------           --------------------------
SelectableItems<Template> TemplateContainer ==Bind==> unknownType? ItemContainer

DefectList user control                           ItemSelection user control
---------------------------------------           --------------------------
SelectableItems<Defect> DefectContainer ==Bind==> unknownType? ItemContainer

Edit: I considered just adding dependency properties to my new ItemSelection user control for all the useful properties in the SelectableItems<T> view model, such as IsAnyItemSelected, etc. That would be fine for most of the properties, but I was hesitant to do it for ObservableCollection<T> Items because I hit the same generic problem as described above, and I didn’t trust things to work okay if I just used IEnumerable instead of ObservableCollection<something>. Maybe I should make an ObservableCollection class that isn’t generic (like in this question)?

  • 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-18T12:40:06+00:00Added an answer on May 18, 2026 at 12:40 pm

    Creating a non-generic ObservableCollection class and then using a value converter to convert my ObservableCollection<T> value to an ObservableCollection seems to have worked.

    Here are the important parts of my ObservableCollection class:

    public class ObservableCollection : ICollection<object>,
        INotifyCollectionChanged
    {
        private ObservableCollection<object> _collection;
    
        public ObservableCollection()
        {
            _collection = new ObservableCollection<object>();
            _collection.CollectionChanged +=
                new NotifyCollectionChangedEventHandler(collectionChanged);
        }
    
        public ObservableCollection(IEnumerable items)
        {
            if (null == items)
            {
                throw new ArgumentNullException("items");
            }
            _collection = new ObservableCollection<object>();
            foreach (object item in items)
            {
                Add(item);
            }
            _collection.CollectionChanged +=
                new NotifyCollectionChangedEventHandler(collectionChanged);
        }
    
        ...stuff necessary to implement ICollection<object>...
    
        public event NotifyCollectionChangedEventHandler CollectionChanged;
    
        void collectionChanged(object sender,
            NotifyCollectionChangedEventArgs e)
        {
            NotifyCollectionChangedEventHandler handler = CollectionChanged;
            if (null != handler)
            {
                handler(this, e);
            }
        }
    }
    

    And here’s the value converter:

    public class EnumerableToObservableCollectionConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter,
            CultureInfo culture)
        {
            if (targetType != typeof(ObservableCollection))
            {
                throw new ArgumentException("Do not use this converter except " +
                    "when going to ObservableCollection");
            }
            var enumerable = value as IEnumerable;
            if (null == enumerable)
            {
                return new ObservableCollection();
            }
            return new ObservableCollection(enumerable);
        }
    
        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            return value;
        }
    }
    

    And I bind like so:

    <local:ItemSelection SelectedItems="{Binding Path=MyViewModel.SelectedItems,
        Mode=OneWay}"
        Items="{Binding Path=MyViewModel.Items, Mode=OneWay,
            Converter={StaticResource observCollConverter}}"
        IsAnyItemSelected="{Binding Path=MyViewModel.IsAnyItemSelected,
            Mode=OneWay}"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a couple of SVN repositories hosted at Unfuddle and I'd like
I currently have an MS Access application that connects to a PostgreSQL database via
I've got a couple of ASP.Net Usercontrols that I am using in different locations
I have a tab control on a form, and a couple different tabs have
Okay, I have a FormView with a couple of child controls in an InsertItemTemplate.
I currently have an application that gets hit with over 20,000 users daily and
I have defined a couple of different roles in my asp.net website : Administrators,
I have a Sql Server 2008 Express database file that's currently being used by
I currently have a single solution that contains both the one application developed so
I have a couple of questions that are somewhat related so I'm posting them

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.