XAML button bound to ReactiveCommand does not get enabled when execution finishes

46 views
Skip to first unread message

Atle

unread,
Feb 20, 2015, 3:38:28 AM2/20/15
to reacti...@googlegroups.com
Hi,

I have a ReactiveCommand bound to a XAML button like this:

XAML:
<Button Content="Update" HorizontalAlignment="Right" Command="{Binding CreateSeries}"/>

ViewModel:

public ReactiveCommand<IList<IChartSeriesViewModel>> CreateSeries { get; protected set; }

In ctor:
CreateSeries = ReactiveCommand.CreateAsyncTask(_ => CreateSeriesImpl());
CreateSeries.Subscribe(chartSeriesViewModels =>
{
    SeriesCollection = new ObservableCollection<IChartSeriesViewModel>(chartSeriesViewModels);
});

The async dummy task:
private async Task<IList<IChartSeriesViewModel>> CreateSeriesImpl()
{
    const int nSimulations = 100;
    IEnumerable<Task<Data>> readDataTasks = Enumerable.Range(0, nSimulations).Select(ReadData);
    Data[] datas = await Task.WhenAll(readDataTasks);
    return datas.Select(CreateChartSeries).ToList();
}

When I press my 'Update' button it id disabled as expected, however, it never gets enabled again even though the task finishes and my plots gets updated. Is there something I am forgetting? Shouldn't the button get enabled automagically when the task finishes?

Another thing, I tried using ReactiveList instead of ObservableCollection, but the plot would never update (SciChart by the way).

Sincerely
Atle 

Phil

unread,
Feb 20, 2015, 1:23:30 PM2/20/15
to reacti...@googlegroups.com
How about like this?

CreateSeries = ReactiveCommand.CreateAsyncTask(_ async => {
SeriesCollection = new ObservableCollection<IChartSeriesViewModel>(await CreateSeriesImpl());
});

--
You received this message because you are subscribed to the Google Groups "ReactiveUI mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reactivexaml...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Phil
Reply all
Reply to author
Forward
0 new messages