|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Collections.ObjectModel;
using SlasheneFramework;
using System.ComponentModel;
namespace DispatcherApplication
{
public class PersonsViewModel : INotifyPropertyChanged
{
readonly IDispatcher _CurrentDispatcher;
readonly IDispatcher<IPersonRepository> _Repository;
public PersonsViewModel(IDispatcher<IPersonRepository> repository, IDispatcher currentDispatcher)
{
_Persons = new ObservableCollection<string>();
_Repository = repository;
_CurrentDispatcher = currentDispatcher ?? new WpfDispatcher();
DoRefresh();
}
public PersonsViewModel(IDispatcher<IPersonRepository> repository)
: this(repository, null)
{
}
private readonly ObservableCollection<string> _Persons;
public ObservableCollection<string> Persons
{
get
{
return _Persons;
}
}
private bool _IsLoading;
public bool IsLoading
{
get
{
return _IsLoading;
}
set
{
if(value != _IsLoading)
{
_IsLoading = value;
if(PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("IsLoading"));
}
}
}
protected void DoRefresh()
{
IsLoading = true;
_Repository.BeginInvoke((IPersonRepository repo) =>
{
var persons = repo.GetPersonsName();
_CurrentDispatcher.BeginInvoke(() =>
{
Persons.Clear();
foreach(var person in persons)
{
Persons.Add(person);
}
IsLoading = false;
});
});
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am currently the CTO of
Metaco, we are leveraging the Bitcoin Blockchain for delivering financial services.
I also developed a tool to make IaaS on Azure more easy to use
IaaS Management Studio.
If you want to contact me, go
this way