You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.7 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
namespace GummingCommon
{
public class ViewProperty<T>
{
private T _value;
public ViewProperty(T defaultValue = default(T))
{
_value = defaultValue;
}
public T Value
{
get { return _value; }
set
{
_value = value;
var handler = ValueChanged;
if (handler != null)
handler();
}
}
public event Action ValueChanged;
}
public class ViewCollectionProperty<T>
{
private readonly MyObservableCollection<T> _collection;
public ViewCollectionProperty()
{
_collection = new MyObservableCollection<T>(_collection_CollectionChanged);
}
public ICollection<T> Collection { get { return _collection; } }
public event Action CollectionChanged;
private void _collection_CollectionChanged()
{
if (CollectionChanged != null)
CollectionChanged();
}
private class MyObservableCollection<T2> : ObservableCollection<T2>
{
private readonly Action _onCollectionChanged;
public MyObservableCollection(Action onCollectionChanged) : base()
{
_onCollectionChanged = onCollectionChanged;
}
protected override void OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
_onCollectionChanged();
}
}
}
}