我愿意使用INC<T>
notify属性更改机制的版本,该版本比Property + Field + RaisePropertyChanged版本更加简洁。
但是,说我有这个ViewModel:
public abstract class PageViewModel : MvxViewModel
{
/// <summary>
/// The is loading
/// </summary>
public readonly INC<bool> IsLoading = new NC<bool>();
/// <summary>
/// The subtitle
/// </summary>
public readonly INC<string> Subtitle = new NC<string>();
/// <summary>
/// The title
/// </summary>
public readonly INC<string> Title = new NC<string>();
现在,假设我在android Activity中,并且我想订阅以下属性:
public partial class MainView : IFragmentHost
{
private void Subscribe(PageViewModel viewModel)
{
viewModel.Title.Changed += (xx) => Whatever;
}
稍等片刻,WeakSubscribe会很好,所以:
viewModel.Title.WeakSubscri...
嗯,很奇怪,我没有自动补全功能。
让我们看看MvxWeakSubscriptionExtensionMethods:
public static class MvxWeakSubscriptionExtensionMethods
{
public static MvxNotifyPropertyChangedEventSubscription WeakSubscribe(this INotifyPropertyChanged source, EventHandler<PropertyChangedEventArgs> eventHandler)
{
return new MvxNotifyPropertyChangedEventSubscription(source, eventHandler);
}
public static MvxValueEventSubscription<T> WeakSubscribe<T>(this EventInfo eventInfo, object source, EventHandler<MvxValueEventArgs<T>> eventHandler)
{
return new MvxValueEventSubscription<T>(source, eventInfo, eventHandler);
}
现在 INC<T>
public interface INC<T> : INotifyChange<T>, INotifyChange
那么,有没有办法弱势认购INC<T>
物业?
插件本身使用以下弱引用进行绑定:
IDisposable _subscription = NotifyChangeEventInfo.WeakSubscribe(_notifyChange, NotifyChangeOnChanged);
哪里NotifyChangeOnChanged
有签名:
protected abstract void NotifyChangeOnChanged(object sender, EventArgs eventArgs);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句