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