|
using System.ComponentModel;
using System.ComponentModel.Composition;
using GalaSoft.MvvmLight;
using SchoolSample.Common;
namespace SchoolSample.ViewModel
{
[Export(ViewModelTypes.MainPageViewModel, typeof(ViewModelBase))]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class MainPageViewModel : ViewModelBase
{
#region "Private Data Members"
private ISchoolModel _schoolModel;
#endregion "Private Data Members"
#region "Constructor"
[ImportingConstructor]
public MainPageViewModel(ISchoolModel orderItModel)
{
_schoolModel = orderItModel;
// set up error handling
_schoolModel.AllowMultipleErrors = false;
_schoolModel.ClearLastError();
// set up event handling
_schoolModel.PropertyChanged += _schoolModel_PropertyChanged;
// set the initial values
IsBusy = _schoolModel.IsBusy;
}
#endregion "Constructor"
#region "Public Properties"
public bool IsBusy
{
get { return _isBusy; }
private set
{
if (value != _isBusy)
{
_isBusy = value;
RaisePropertyChanged("IsBusy");
}
}
}
private bool _isBusy;
#endregion "Public Properties"
#region "Private Methods"
/// <summary>
/// Event handler for PropertyChanged
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void _schoolModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "IsBusy":
IsBusy = _schoolModel.IsBusy;
break;
}
}
#endregion "Private Methods"
}
}
|
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.
Weidong has been an information system professional since 1990. He has a Master's degree in Computer Science, and is currently a MCSD .NET