Hi, you can build class with event and in this class include HandleProjectItem. Try following demo.
XAML:
<Page
x:Class="App1.Page08"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App08"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.DataContext>
<local:ViewModel/>
</Page.DataContext>
<StackPanel>
<Button Content="Start read" Command="{Binding Cmd}"/>
<TextBox/>
<ListBox ItemsSource="{Binding View}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Info}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Page>
And classes:
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.UI.Xaml.Controls;
namespace App08
{
public class ViewModel : INotifyPropertyChanged
{
ObservableCollection<Project> col;
public ObservableCollection<Project> View { get => col; }
DataModel m;
public ICommand Cmd
{
get => new RelayCommand(async (state) =>
{
if (m == null)
{
m = new DataModel();
m.DataLoaded += M_DataLoaded;
}
await m.HandleProjectItem(null);
});
}
private void M_DataLoaded(object sender, EventArgs e)
{
col = m.Collection;
OnPropertyChanged(nameof(View));
}
public event PropertyChangedEventHandler PropertyChanged;
internal void OnPropertyChanged([CallerMemberName] string propName = "") =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
public class Project
{
public string Info { get; set; }
}