-
Notifications
You must be signed in to change notification settings - Fork 1
Calculated Properties
Dmitry Shechtman edited this page Mar 26, 2017
·
5 revisions
-
Install
Ditto.AsyncMvvm.Calculated. -
Derive your view model from
CalculatedAsyncBindableBase:using Ditto.AsyncMvvm.Calculated; class UniversalAnswerViewModel : CalculatedAsyncBindableBase { }
-
Implement the asynchronous method for calculating the value of the trigger property:
private async Task<int?> GetAnswerAsync() { await Task.Delay(TimeSpan.FromDays(7500000 * 365.25)); return 42; }
-
Define the trigger property:
public int? Answer { get { return Property.Get(GetAnswerAsync); } }
-
Define the calculated property:
public string AnswerString { get { return Property.Calculated(() => Answer.HasValue ? Answer.Value.ToString() : null); } }
Calculated Properties Copyright (c) 2014 StephenCleary