mirror of
https://github.com/PacktPublishing/Learn-WinUI-3-Second-Edition.git
synced 2026-06-20 12:23:09 +00:00
Fix loading existing item on item details
This commit is contained in:
@@ -41,12 +41,31 @@ namespace MyMediaCollection.ViewModels
|
||||
PopulateLists();
|
||||
}
|
||||
|
||||
public void InitializeItemDetailData(int itemId)
|
||||
public async Task InitializeItemDetailDataAsync(int itemId)
|
||||
{
|
||||
_selectedItemId = itemId;
|
||||
await PopulateExistingItemAsync(_dataService);
|
||||
IsDirty = false;
|
||||
}
|
||||
|
||||
private async Task PopulateExistingItemAsync(IDataService dataService)
|
||||
{
|
||||
if (_selectedItemId > 0)
|
||||
{
|
||||
var item = await _dataService.GetItemAsync(_selectedItemId);
|
||||
Mediums.Clear();
|
||||
|
||||
foreach (string medium in dataService.GetMediums(item.MediaType).Select(m => m.Name))
|
||||
Mediums.Add(medium);
|
||||
|
||||
_itemId = item.Id;
|
||||
ItemName = item.Name;
|
||||
SelectedLocation = item.Location.ToString();
|
||||
SelectedItemType = item.MediaType.ToString();
|
||||
SelectedMedium = item.MediumInfo.Name;
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulateLists()
|
||||
{
|
||||
ItemTypes.Clear();
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace MyMediaCollection.Views
|
||||
|
||||
public ItemDetailsViewModel ViewModel;
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
protected async override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace MyMediaCollection.Views
|
||||
|
||||
if (itemId > 0)
|
||||
{
|
||||
ViewModel.InitializeItemDetailData(itemId);
|
||||
await ViewModel.InitializeItemDetailDataAsync(itemId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user