/// <summary> /// Applies the middleware on the specified object. /// </summary> /// <param name="object">The object.</param> /// <returns/> public IBootstrapperWithContainer <AutofacAdapter, ContainerBuilder> Apply(IBootstrapperWithContainer <AutofacAdapter, ContainerBuilder> @object) { EventHandler strongHandler = ObjectOnInitializationCompleted; @object.InitializationCompleted += WeakDelegate.From(strongHandler); return(@object); }
public ShellViewModel( IViewModelCreatorService viewModelCreatorService) { _viewModelCreatorService = viewModelCreatorService; EventHandler strongHandler = OnLoggedInSuccessfully; LoginViewModel.LoggedInSuccessfully += WeakDelegate.From(strongHandler); }
public ShellViewModel( ILoginService loginService, IDataService dataService) { _loginService = loginService; _dataService = dataService; EventHandler strongHandler = OnLoggedInSuccessfully; LoginViewModel.LoggedInSuccessfully += WeakDelegate.From(strongHandler); }
/// <summary> /// Raises the <see cref="E:CollectionChanged" /> event. /// </summary> /// <param name="e">The <see cref="NotifyCollectionChangedEventArgs"/> instance containing the event data.</param> protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e) { if (_internalSelectionHandler == null) { _internalSelectionHandler = WeakDelegate.From(InternalIsSelectedChanged); } Action <TItem> removeHandler = a => { if (a is INotifyPropertyChanged) { ((INotifyPropertyChanged)a).PropertyChanged -= _internalSelectionHandler; } Unselect(a); }; Action <TItem> addHandler = (a) => { if (a is INotifyPropertyChanged) { ((INotifyPropertyChanged)a).PropertyChanged += _internalSelectionHandler; } if (_selectedItems.Count == 0 && IsSelectionRequired) { Select(a); } }; switch (e.Action) { case NotifyCollectionChangedAction.Add: e.NewItems.Cast <TItem>().ForEach(addHandler); break; case NotifyCollectionChangedAction.Remove: e.OldItems.Cast <TItem>().ForEach(removeHandler); break; case NotifyCollectionChangedAction.Replace: e.OldItems.Cast <TItem>().ForEach(removeHandler); e.NewItems.Cast <TItem>().ForEach(addHandler); break; case NotifyCollectionChangedAction.Reset: Debug.Assert(false, "We should never be here. Check base class impl"); break; default: throw new ArgumentOutOfRangeException(); } base.OnCollectionChanged(e); }
/// <summary> /// Override this method to inject custom logic on item creation. /// </summary> /// <param name="item">The item.</param> protected override void OnCreated(TItem item) { if (_internalSelectionHandler == null) { _internalSelectionHandler = WeakDelegate.From(InternalIsSelectedChanged); } Action <TItem> addHandler = (a) => { if (a is INotifyPropertyChanged) { ((INotifyPropertyChanged)a).PropertyChanged += _internalSelectionHandler; } if (_selectedItems.Count == 0 && IsSelectionRequired) { Select(a); } }; addHandler(item); }
/// <summary> /// Initializes a new instance of the <see cref="ErrorInfoViewModel{T}"/> class. /// </summary> /// <param name="model">The model.</param> protected ErrorInfoViewModel(T model) : base(model) { var properties = GetType().GetTypeInfo().DeclaredProperties; foreach (var propertyInfo in properties) { var shouldDisplayAttributes = propertyInfo.GetCustomAttributes(typeof(ShouldDisplayErrorInfoAttribute), true) .OfType <ShouldDisplayErrorInfoAttribute>().ToArray(); if (shouldDisplayAttributes.Length == 1) { var shouldDisplayAttribute = shouldDisplayAttributes[0]; if (shouldDisplayAttribute.ShouldDisplay) { _interestingProperties.Add(propertyInfo.Name); _isPropertyChanged.TryAdd(propertyInfo.Name, false); } } } PropertyChanged += WeakDelegate.From(OnPropertyChanged); }