public void Subscribe(INotifyPropertyChanged handler) { // If we're reapplying, we don't want to double subscribe Unsubscribe(); _listener = new WeakPropertyChangedProxy(handler, _changeHandler); }
public void Unsubscribe() { var listener = _listener; if (listener != null) { listener.Unsubscribe(); _listener = null; } }
public void Subscribe(INotifyPropertyChanged handler) { if (ReferenceEquals(handler, _listener?.Source?.Target)) { // Already subscribed return; } // Clear out the old subscription if necessary Unsubscribe(); _listener = new WeakPropertyChangedProxy(handler, _changeHandler); }
public void Subscribe(INotifyPropertyChanged handler) { INotifyPropertyChanged source; if (_listener != null && _listener.Source.TryGetTarget(out source) && ReferenceEquals(handler, source)) { // Already subscribed return; } // Clear out the old subscription if necessary Unsubscribe(); _listener = new WeakPropertyChangedProxy(handler, _changeHandler); }
public MethodToCommandConverter(Delegate action) { var target = action.Target; var canExecuteMethodName = "Can" + action.Method.Name; var parameters = action.Method.GetParameters(); var parameterInfo = parameters.Length == 0 ? null : parameters[0].ParameterType; if (parameterInfo == null) { execute = CreateExecute(target, action.Method); } else { execute = CreateExecute(target, action.Method, parameterInfo); } var canExecuteMethod = action.Method.DeclaringType.GetRuntimeMethods() .FirstOrDefault(m => m.Name == canExecuteMethodName && m.GetParameters().Length == 1 && m.GetParameters()[0].ParameterType == typeof(object)); if (canExecuteMethod == null) { canExecute = AlwaysEnabled; } else { canExecute = CreateCanExecute(target, canExecuteMethod); dependencyProperties = canExecuteMethod .GetCustomAttributes(typeof(Metadata.DependsOnAttribute), true) .OfType <Metadata.DependsOnAttribute>() .Select(x => x.Name) .ToArray(); if (dependencyProperties.Any() && target is INotifyPropertyChanged inpc) { propertyChangedEventHandler = OnPropertyChanged; weakPropertyChanged = new WeakPropertyChangedProxy(inpc, propertyChangedEventHandler); } } }