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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:33:42+00:00 2026-06-08T09:33:42+00:00

I am trying to implement custom ObservableCollection Which will have current (selected) item property

  • 0

I am trying to implement custom ObservableCollection Which will have current (selected) item property which can be directly bound from XAML This is sample code I got so far Could someone point me to the right direction? the idea here is to set listviews’ selected item property directly to its itemsources’ Currentitem and provide Action which will take argument as current item. this action will be set from viewmodel.

public class ItemAwareObservableCollection<T> : ObservableCollection<T>
{
    private readonly Action<T> _selectionCallback;
    private T _currentItem;

    public T CurrentItem
    {
        get { return _currentItem; }
        set
        {
            if(_currentItem.Equals(value))
            _currentItem = value;
            OnPropertyChanged(new PropertyChangedEventArgs("CurrentItem"));
            _selectionCallback(value);
        }
    }

    public ItemAwareObservableCollection(Action<T> selectionCallback)
    {
        _selectionCallback = selectionCallback;
    }

    public ItemAwareObservableCollection(Action<T> selectionCallback, IEnumerable<T> collection)
        : base(collection) { _selectionCallback = selectionCallback; }

    public ItemAwareObservableCollection(Action<T> selecytionCallback, List<T> list)
        : base(list) { _selectionCallback = selecytionCallback; }
}

and this is sample usage from viewmodel

get { return new ItemAwareObservableCollection<Companies>(onSelecttionchange, Resolve<ICompanyService>().Companies); }

inside XAML View I would like to bind this collection to the ItemSource of Llistview (this works perfectly), but I would like to bind its selecteditem property to CurrentItem of this collectiion

  • 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-08T09:33:44+00:00Added an answer on June 8, 2026 at 9:33 am

    No, I would indeed use CurrentItem of ICollectionView and in your XAML use IsSynchronizedWithCurrentItem

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

Sidebar

Related Questions

I'm trying to implement a custom aggregate function in Postgres which will average directions
I was trying to implement custom validation attribute by inheriting from ValidationAttribute and found
I'm trying to implement some custom model metadata in ASP.NET MVC 3. I can't
I'm trying to implement a custom tab bar which is scrollable and has paging
I'm trying to implement a custom validation annotation in Seam. We have a list
I'm trying to implement a custom log4net logger/logmanager so that I can add a
I am trying to implement a custom UIView which is basically a pie menu
I'm trying to implement custom suggestions for qsb. I have added CREATE TABLE IF
I'm trying to implement a custom class for dataannotations that retrieves error messages from
I'm trying to implement a custom TrackingParticipant for WF 4. I can write the

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.