Language: C#
VM Base
public class StoryFrameEditorViewModel : ViewModel { public StoryFrameEditorViewModel() { _template = Field<StoryFrameTemplate>("Template"); } private BackingField<StoryFrameTemplate> _template; public StoryFrameTemplate Template { get { return _template.Value; } set { _template.Value = value;} } } public abstract class ViewModel : INotifyPropertyChanged { private Dictionary<string, object> _data; public void RaisePropertyChanged(string property) { var handler = PropertyChanged; if (handler != null) { PropertyChanged(this, new PropertyChangedEventArgs(property)); } } public BackingField<T> Field<T>(string property) { return new BackingField<T>(() => RaisePropertyChanged(property)); } public event PropertyChangedEventHandler PropertyChanged; } public class BackingField<T> { private readonly string _propertyName; private readonly Action _notifyAction; private T _value; public T Value { get { return _value; } set { if (!Equals(value, _value)) { _value = value; _notifyAction(); } } } public BackingField(Action notifyAction) { _notifyAction = notifyAction; } }
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

