My ViewModel has a 30 second data refresh service delegate method:
public Task OnDataRefreshed(List<MyType> data)
{
this.Data = data;
LongRunningGetDetailsAsync();
return Task.FromResult(0);
}
Public property Data is displayed and refreshed in the view properly.
The intention here is not to await the async task (fire-and-forget) LongRunningGetDetailsAsync() as it will introduce a significant delay before the Data is displayed if executed sync. I want to show Data ASAP and then let async task fetch the details at its own pace and let the view binding catch up then.
private async Task LongRunningGetDetailsAsync()
{
foreach (MyType dataitem in this.Data)
{
dataitem.Details = await _apiEndpointService.GetDetails(dataitem.Id);
}
}
LongRunningGetDetailsAsync() is where the binding is not firing. I set a break point at the end of LongRunningGetDetailsAsync watching Data.Details - the Data.Details are there, but it is never displayed in the view.
Thank you in advance for your time!
EDIT: Changed to
public async Task OnDataRefreshed(ObservableCollection<MyType> data)
{
this.Data = data;
await LongRunningGetDetailsAsync();
}
- still have the same issue.
Datais bound toMvx.MvxListView. If the list is long and an item happens to be out of view, once scrolled to, it displays the updated model OK.
"Data":
public class MyType
{
public string MyProperty { get; set; }
public string Details { get; set; }
}
private ObservableCollection<MyType> _data;
public ObservableCollection<MyType> Data
{
get { return _data; }
set
{
if (SetProperty(ref _data, value))
{
RaisePropertyChanged(() => Data);
}
}
}
View binding:
<Mvx.MvxListView
local:MvxBind="ItemsSource Data"
local:MvxItemTemplate="@layout/listitem"
... />
listitem:
<TextView local:MvxBind="Text MyProperty" ...
<TextView local:MvxBind="Text Details" ...
INotifyPropertyChangedinterface? How does the propertyDetailslook like? - DefaultRaisePropertyChanged(() => Data);onset, View - please see the addition above - StackDetailsproperty - that is the one changing. YourDatadoesn't (in the callDetails = ..). Also, try to avoid setters for your collections. If you need to add new data then useClearandAdd[Range]instead. - Default