How do i get a viewmodel object to remove itself from its containing observable Collecttion?

Posted on 2011-10-07
Last Modified: 2012-05-12
I am building an application that has a ObservableCollection containing a bunch of UserControls.  The usercontrols are added because of a DataTemplate.  The object actually added to the collection is an MVVM view Model obejct.  

My usercontrol has a button on it that when pressed should cause itself to be removed from the list.  Now i can Implement this as an event by calling a custom event in the in the usercontrol code behind and catching it in another list object derived from the ObservableCollection.  but i would like to know if i can get the same behavior through the use of a command attachted to that button.
Question by:kmitch62
    1 Comment

    Accepted Solution

    I got it.  simply created a new custom event in the ViewModel and updated the Observable list to catch the event when fired.

    Had the command redirect to the method that raised the event then done.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now