public static DependencyProperty RegisterAttached <TOwner>(Func <TOwner, object, Task> reaction, Type declaringType, [CallerMemberName] string propertyName = null) where TOwner : DependencyObject { propertyName = AcquirePropertyName(propertyName); SignalRegistrationService <TOwner> .RegisterMessage(propertyName, reaction); return(DependencyProperty.RegisterAttached(propertyName, typeof(IReceivable), declaringType, new PropertyMetadata(default(IReceivable), (o, args) => SignalAttachedPropertyChanged((TOwner)o, args)))); }
private static void SignalAttachedPropertyChanged <TOwner>(TOwner owner, DependencyPropertyChangedEventArgs args) where TOwner : class { var oldValue = args.OldValue as AsyncRequest; var newValue = args.NewValue as AsyncRequest; var propertyName = args.Property.Name; SignalRegistrationService <TOwner> .UpdateInstanceValue(owner, oldValue, newValue, propertyName); }
/// <summary> /// Registers an attached message asynchronous reaction. /// </summary> /// <typeparam name="TOwner">Type of DependencyObject which will react this message (e.g. Window)</typeparam> /// <typeparam name="TRequest">Type of passed data (e.g. string)</typeparam> /// <param name="reaction">An asynchronous action which will take place after the message is received</param> /// <param name="declaringType">Type which declares this message. (Not the type it will be attached to, but the type of that static class you're currently implementing!)</param> /// <param name="propertyName">Name of the property to register. Skip it! It is resovled automatically.</param> /// <returns>Registered attached property</returns> public static DependencyProperty RegisterMessageAttached <TOwner, TRequest>(Func <TOwner, TRequest, Task> reaction, Type declaringType, [CallerMemberName] string propertyName = null) where TOwner : DependencyObject { if (typeof(TRequest) == typeof(object)) { return(RegisterAttached((Func <TOwner, object, Task>)(object) reaction, declaringType, propertyName)); } propertyName = AcquirePropertyName(propertyName); SignalRegistrationService <TOwner> .RegisterMessage(propertyName, reaction); return(DependencyProperty.RegisterAttached(propertyName, typeof(IMessage <TRequest>), declaringType, new PropertyMetadata(default(IMessage <TRequest>), (o, args) => SignalPropertyChanged((TOwner)o, args)))); }
public static DependencyProperty Register <TOwner, TResult>( Func <TOwner, Task <TResult> > reaction, [CallerMemberName] string propertyName = null) where TOwner : DependencyObject { if (typeof(TResult) == typeof(object)) { return(Register((Func <TOwner, Task <object> >)(object) reaction, propertyName)); } propertyName = AcquirePropertyName(propertyName); SignalRegistrationService <TOwner> .Register(propertyName, reaction); return(DependencyProperty.Register( propertyName, typeof(IResponsive <TResult>), typeof(TOwner), new PropertyMetadata( default(IResponsive <TResult>), (o, args) => SignalPropertyChanged((TOwner)o, args)))); }