I apologize in advance if my question is a bit vague.
I am looking into and learning reactiveui which I find a very interesting concept. For that, I am building a small application using WPF and Prism and I am having some difficulties understanding the way commands are build in the View Models.
I have an example which, if complete, will hopefully clarify things for me a little bit:
I would like to have a grid that displays some data. This data is loaded from a web service and my goal is to load it once when the view is shown to the user and then to reload it every x times (once a minute, for example) or when explicitly triggered from a button in the View.
So, my View Model currently looks like:
public class MyPageViewModel : ReactiveValidatedObject
{
/// <summary>
/// Collection of tickets
/// </summary>
public ReactiveCollection<TicketModel> Tickets { get { return _Tickets.Value; } }
/// <summary>
/// Private store of tickets
/// </summary>
private ObservableAsPropertyHelper<ReactiveCollection<TicketModel>> _Tickets { get; set; }
/// <summary>
/// The service which retrieves the tickets
/// </summary>
private ITicketService _ticketService;
public MyPageViewModel() : this(null) { }
public MyPageViewModel(ITicketService ticketService)
{
LoadTickets = new ReactiveAsyncCommand(null, 0);
}
/// <summary>
/// A command which exposes the load action for the tickets
/// </summary>
public ReactiveAsyncCommand LoadTickets { get; private set; }
private void loadTickets()
{
//returns a List<TicketModel>
var tickets = _ticketService.GetTickets();
}
}
My questions are:
1) How do I register an async command which will be fired every x times and will call the internal loadTickets function that will reload the Ticket storage? This command will also be fired by the exposed command LoadTickets.
2) In the function, loadTickets I will fetch each time a List from the service. How do I convert this list to the ReactiveCollection that is exposed to the UI.