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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:34:27+00:00 2026-06-08T13:34:27+00:00

I’m writing simple WP7 app to study ReactiveUI. I want to show a collection

  • 0

I’m writing simple WP7 app to study ReactiveUI.
I want to show a collection on the screen, items should be selectable, and I want to have a Command which removes all selected items from the collection. Also the command must be executable only when there is at least one selected item.
I’ve got a collection defined in this way:

Persons = model.Persons
                .CreateDerivedCollection(x => new PersonViewModel(x));

In PersonViewModel I have a property:

private bool _isSelected;
public bool IsSelected
{
    get { return _isSelected; }
    set { this.RaiseAndSetIfChanged(x => x.IsSelected, ref _isSelected, value); }
}

There is no information about selection state in model, just in viewModel.
In Page ViewModel I have this code:

Persons = model.Persons.CreateDerivedCollection(x => new PersonViewModel(x));
Persons.ChangeTrackingEnabled = true;

var deleteSelectedCanExecute = Persons.ItemChanged
                                  .Select(_ => Persons .Any(p => p.IsSelected));

DeleteSelectedCommand = new ReactiveCommand
                (
                       deleteSelectedCanExecute
                );
DeleteSelectedCommand.Subscribe(
                x => RemoveSelected()
                );

and a method:

   private void RemoveSelected()
    {
        var res = Persons.Where(p => p.IsSelected)
             .Select(x => x.Model).ToList();
        foreach (var person in res)
        {
            _model.Persons.Remove(person);
        }
    }

first question (not so important, I think I can find the solution by myself):
when I run an app the DeleteSelected button is Active.DeleteSelectedCommand.CanExecute does not fires. However after selecting/deselection any item – button states works fine.

and the main problem:

After I run DeleteSelectedCommand it removes all selected items (I see it in the debugger). And then I got “NotSupportedException” with following stack trace:

   at System.Threading.Interlocked.Decrement(Int64& location)
   at ReactiveUI.RefcountDisposeWrapper.Release()
   at ReactiveUI.ReactiveCollection`1.removeItemFromPropertyTracking(PersonViewModel toUntrack)
   at ReactiveUI.ReactiveCollection`1.<setupRx>b__18(PersonViewModelx)
   at System.Reactive.AnonymousObserver`1.Next(PersonViewModelvalue)
   at System.Reactive.AbstractObserver`1.OnNext(PersonViewModelvalue)
   at System.Reactive.AutoDetachObserver`1.Next(PersonViewModelvalue)
   at System.Reactive.AbstractObserver`1.OnNext(PersonViewModelvalue)
   at System.Reactive.ScheduledObserver`1.<>c__DisplayClass4.<Next>b__2()
   at System.Reactive.ScheduledObserver`1.<EnsureActive>b__0(Action self)
   at System.Reactive.Concurrency.Scheduler.<Schedule>b__0(Action`1 _action, Action`1 self)
   at System.Reactive.Concurrency.Scheduler.<>c__DisplayClass9`1.<InvokeRec1>b__6(Action`1 state1)
   at System.Reactive.Concurrency.Scheduler.InvokeRec1[TState](IScheduler scheduler, Pair`2 pair)
   at System.Reactive.Concurrency.DispatcherScheduler.<>c__DisplayClass1`1.<Schedule>b__0()
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at System.Delegate.DynamicInvokeOne(Object[] args)
   at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
   at System.Delegate.DynamicInvoke(Object[] args)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
   at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
   at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
   at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
   at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)

So I’m doing it wrong, but what’s the problem? I can’t understand from the ST. What’s the right way to implement this behaviour. It’s so common isn’t it?

upd

If I remove all code about deleteSelectedCanExecute and run program – it crashes. If i remove Participants.ChangeTrackingEnabled = true; – it works as I expect.

  • 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-08T13:34:29+00:00Added an answer on June 8, 2026 at 1:34 pm

    Anton, you are the proud owner of a new ReactiveUI commit – build from source and your crash should go away.

    As to your question about the selection, this is one scenario that is a bit tricky to do at the moment if the collection can change sizes. Code somewhere must not only subscribe to each item in the collection, it must also keep a list of which items are being added or removed (i.e. there are two ways to no longer be selected, Item.IsSelected going from true => false, or Item being removed).

    If you don’t have a list that changes rapidly, you can do this in a somewhat inefficient though far easier way:

    var cmd = new ReactiveCommand(
        Persons.ItemsCountChanged.Select(_ => 
            Persons.Any(x => x.IsSelected)));
    

    Incidentally, this solution also doesn’t require ChangeTrackingEnabled, so you don’t need to work around the bug I just fixed.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I want to show the soap response to UIWebview.. my soap response is, <p><img
I am writing an app with both english and french support. The app requests
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.