В моей ViewModel мне приходится обновлять некоторые свойства при каждом возникновении события.
Хотя моя ViewModel обновляет свойства, эти изменения не отражаются в пользовательском интерфейсе.
Вот моя (упрощенная) ViewModel:
Код: Выделить всё
public class DashboardViewModel : ReactiveObject, IAsyncHandle
{
private readonly IQueryHandler raceQueryHandler;
public DashboardViewModel(IQueryHandler raceQueryHandler)
{
this.raceQueryHandler = raceQueryHandler;
// Here the method updates the properties & UI is updated
SetRaceProperties();
}
[Reactive]
public string NumberOfRaces { get; set; }
[Reactive]
public string NumberOfFinishedRaces { get; set; }
[Reactive]
public string NumberOfPendingRaces { get; set; }
// Whenever a 'RaceCreatedEvent' has fired, this method is executed
public async Task HandleAsync(RaceCreatedEvent domainEvent)
{
// Here the method updates the properties, but the UI is NOT updated
await SetRaceProperties();
}
private async Task SetRaceProperties()
{
var data = await raceQueryHandler.HandleMultipleAsync(null);
this.NumberOfRaces = $"{data.Count()} aangemaakte races";
this.NumberOfPendingRaces = $"{data.Where(r => r != null && !r.Finished && !r.Started).Count()} races in afwachting";
this.NumberOfFinishedRaces = $"{data.Where(r => r != null && r.Finished).Count()} afgelopen races";
}
}
Каждый раз, когда метод SetRaceProperties запускается из моего обработчика событий, обновляются свойства, но не пользовательский интерфейс.
Вот моя привязка представления:
Код: Выделить всё
Заранее спасибо!
Мобильная версия