Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could also do this using <a href="http://github.com/xpaulbettsx/ReactiveXaml" rel="nofollow noreferrer">ReactiveXaml</a>, though since your CurrentWidget and Widgets are both mutable, you can't make it as clean (there's a class called <a href="http://blog.paulbetts.org/index.php/2010/07/05/reactivexaml-series-implementing-search-with-observableaspropertyhelper/" rel="nofollow noreferrer">ObservableAsPropertyHelper</a> which will update a property based on an IObservable and fire the RaisePropertyChanged):</p> <pre><code>public class ViewModel { public ViewModel() { // These return a Func that wraps an async call in an IObservable&lt;T&gt; // that always yields only one item (the result of the call) var QueryAsObservable = Observable.FromAsyncCommand&lt;IEnumerable&lt;Widget&gt;&gt;(WebService.BeginQuery, WebService.EndQuery); var LoadAsObservable = Observable.FromAsyncCommand&lt;Widget&gt;(WebService.BeginLoad, WebService.EndLoad); // Create a new command QueryAndLoad = new ReactiveAsyncCommand(); // QueryAndLoad fires every time someone calls ICommand.Execute // The .Do is the hacky part, for sync calls it's hidden by RegisterAsyncFunction var async_results = QueryAndLoad.SelectMany(_ =&gt; QueryAsObservable()) .Do(_ =&gt; DoTranslate.AsyncCompletedNotification.OnNext(new Unit())); // Query up the Widgets async_results.Subscribe(x =&gt; x.Run(Widgets.Add)); // Now execute the Load async_results.SelectMany(_ =&gt; LoadAsObservable()) .Subscribe(x =&gt; CurrentWidget = x); QueryAndLoad.Execute(); } public ReactiveAsyncCommand QueryAndLoad {get; private set; } public ObservableCollection&lt;Widget&gt; Widgets {get; private set; } public Widget CurrentWidget {get; set; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload