Init
This commit is contained in:
66
ViewModels/ViewModelBase.cs
Normal file
66
ViewModels/ViewModelBase.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace TradeBlotter.ViewModels
|
||||
{
|
||||
public interface IPersistentViewModel
|
||||
{
|
||||
SaveParameters GetSaveParameters();
|
||||
void SetSaveParameters(SaveParameters saveParameters);
|
||||
bool CanPersist();
|
||||
}
|
||||
public abstract class ModelBase : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
protected virtual bool ThrowOnInvalidPropertyName
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
this.VerifyPropertyName(propertyName);
|
||||
PropertyChangedEventHandler handler = PropertyChanged;
|
||||
if (handler != null)
|
||||
{
|
||||
var e = new PropertyChangedEventArgs(propertyName);
|
||||
handler(this, e);
|
||||
}
|
||||
}
|
||||
public void VerifyPropertyName(string propertyName)
|
||||
{
|
||||
if (TypeDescriptor.GetProperties(this)[propertyName] == null)
|
||||
{
|
||||
string message = "Invalid property name: " + propertyName;
|
||||
if (this.ThrowOnInvalidPropertyName) throw new Exception(message); else Debug.Fail(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
public abstract class ViewModelBase : ModelBase, IDisposable, IPersistentViewModel
|
||||
{
|
||||
protected ViewModelBase()
|
||||
{
|
||||
}
|
||||
public abstract SaveParameters GetSaveParameters();
|
||||
public abstract void SetSaveParameters(SaveParameters saveParameters);
|
||||
public abstract bool CanPersist();
|
||||
public virtual void Dispose()
|
||||
{
|
||||
this.OnDispose();
|
||||
}
|
||||
public virtual String DisplayName { get; protected set; }
|
||||
protected virtual void OnDispose()
|
||||
{
|
||||
}
|
||||
#if DEBUG
|
||||
~ViewModelBase()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user