0
我願意使用INC<T>
版本的notify屬性更改mecanism,它比Property + Field + RaisePropertyChanged版本更簡潔。FieldBinding和弱引用
但是,讓我們說我有這樣的視圖模型:
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的活動,我想訂閱這些屬性:
public partial class MainView : IFragmentHost
{
private void Subscribe(PageViewModel viewModel)
{
viewModel.Title.Changed += (xx) => Whatever;
}
在第二不過,這將是很好WeakSubscribe給他們,讓:
viewModel.Title.WeakSubscri...
Mmmmh怪異,我沒有對自動完成那。
讓我們來看看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>
財產?