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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:43:01+00:00 2026-06-09T19:43:01+00:00

I was working on a proof of concept for binding to an ObservableCollection property

  • 0

I was working on a proof of concept for binding to an ObservableCollection property which returns the result of a delegate. The delegate has a property set up for it also, so that I can change the expression used, and it triggers OnPropertyChanged for the Collection. This allows me to bind a ComboBox to the Collection, and upon changing the expression/query the available choices in the ComboBox will change too.

Code:

public delegate List<string> Del();

private Del _query;
public Del Query
{
    get
    {
        return _query;
    }
    set
    {
        _query= value;
        OnPropertyChanged("BindList");
    }
}

private ObservableCollection<string> bindList;
public ObservableCollection<string> BindList
{
    get
    {
        var results = Query();
        bindList = new ObservableCollection<string>(results);
        return bindList;
    }
    set
    {//I believe I need this setter for the extra functionality provided by ObservableCollections over Lists
        if(bindList != value) {
            bindList = value;
            OnPropertyChanged("BindList");
        }
    }
}

Since this works, I’m wanting to make a class out of it that will be simple to bind to. I’m asking for guidance on how to do so. I’ve thought some about subclassing ObservableCollection, but was having issues with how to set the Items. I’ve also considered just a custom class using interfaces like IEnumerable and ICollectionView (along with the notification Interfaces).

So in summary, how would you build a class to incorporate a collection whose members are based on a delegate query (LINQ to be specific) with regard to subclassing/interfaces?

Thanks in advance.

  • 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-09T19:43:02+00:00Added an answer on June 9, 2026 at 7:43 pm

    Here’s what I’ve come up with so far. Hasn’t had a lot of testing yet, but so far its looking pretty good.

    public class DynamicCollection<T> : IEnumerable, INotifyCollectionChanged
    {
        public ICollectionView Collection { get; private set; }
    
        public delegate List<T> Del();
    
        private Del query;
        public Del Query
        {
            get
            {
                return query;
            }
            set
            {
                if (query != value)
                {
                    query = value;//set the new query
                    T currentItem = (T)Collection.CurrentItem;//save current item
                    Collection = new PagedCollectionView(Query());//recreate collection with new query
                    Collection.MoveCurrentTo(currentItem);//move current to the previous current (if it doesn't exist, nothing is selected)
                    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));//Notify colleciton has changed.
                }
            }
        }
    
        public DynamicCollection()
        {
            Collection = new PagedCollectionView(new List<T>());//empty collection
        }
    
        public DynamicCollection(IEnumerable<T>collection)
        {
            Collection = new PagedCollectionView(collection);
        }
    
        public DynamicCollection(Del delegateQuery)
        {
            Query = delegateQuery;
        }
    
        #region IEnumerable Members
        public IEnumerator GetEnumerator()
        {
            return Collection.GetEnumerator();
        }
        #endregion IEnumerable Members
    
        #region INotifyCollectionChanged Members
        public event NotifyCollectionChangedEventHandler CollectionChanged;
        protected void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            NotifyCollectionChangedEventHandler handler = CollectionChanged;
            if (handler != null)
            {
                CollectionChanged(this, e);
            }
        }
        #endregion INotifyCollectionChanged Members
    }
    

    It can be bound to in a ComboBox using ItemsSource="{Binding Path=myCollection, Mode=TwoWay}" (given you have DyamicCollection myCollection set up as a property in your ViewModel/data context).

    It all works by setting the Query, which in my case I give a LINQ to XML query that returns a List. The Collection updates on this, and the bound ComboBox reflects this update.

    Please feel free to critique this. I’m fairly certain I’ve got something off, or maybe there is even a better way to do this. I’m open to feedback, and will update this answer as it evolves.

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

Sidebar

Related Questions

I'm working on a sort of proof-of-concept for a project that approximates Firebug's inspector
Working with an undisclosed API, I found a function that can set the number
I'm working on a proof of concept app (which will hopefully grow) where users
I'm working on a prototype system which will act as a proof of concept
Here is the scenario. I have a working VSX package Proof of Concept that
In a proof-of-concept project I'm working on, I have a generic abstract class that
I'm working on a project that's been accepted as a proof of concept and
I am trying to test a proof of concept that I can run a
I'm working on proof of concept project. That is using a UITableView to display
I'm new mobile development and i'm working on an proof of concept application on

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.