You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
downkyi/DatabaseManager/ViewModels/ViewHeaderViewModel.cs

58 lines
1.5 KiB

using DownKyi.Core.Storage.Database;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Windows;
namespace DatabaseManager.ViewModels
{
public class ViewHeaderViewModel : BindableBase, INavigationAware
{
private ObservableCollection<Header> headerList;
public ObservableCollection<Header> HeaderList
{
get { return headerList; }
set { SetProperty(ref headerList, value); }
}
public ViewHeaderViewModel()
{
HeaderList = new ObservableCollection<Header>();
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
public async void OnNavigatedTo(NavigationContext navigationContext)
{
await Task.Run(() =>
{
HeaderDb headerDb = new HeaderDb();
var headers = headerDb.QueryAll();
if (headers == null)
{
return;
}
Application.Current.Dispatcher.Invoke(new Action(() =>
{
HeaderList.Clear();
foreach (var cover in headers)
{
HeaderList.Add(cover);
}
}));
});
}
}
}