using IFramework.Message;
using System;
namespace IFramework.MVVM
{
///
/// 界面
///
public abstract class View : IDisposable
{
private ObservableValue _context = new ObservableValue(null);
///
/// 数据绑定
///
protected ObservableObjectHandler handler;
///
/// VM
///
public ViewModel context
{
get { return _context; }
set
{
_context.value = value;
}
}
///
/// ctor
///
public View()
{
handler = new ObservableObjectHandler();
_context.Subscribe(BindProperty);
}
///
/// 绑定数据
///
protected virtual void BindProperty()
{
handler.UnSubscribe();
}
///
/// 释放
///
public void Dispose()
{
OnDispose();
handler.UnSubscribe();
}
///
/// 释放时
///
protected virtual void OnDispose() { }
///
/// 发布消息
///
///
protected void Publish(IEventArgs message)
{
(context as IViewModel).Listen(message);
}
}
///
/// 方便书写
///
///
public abstract class View : View where T : ViewModel
{
///
/// 方便书写
///
public T Tcontext { get { return context as T; } set { context = value; } }
}
}