コード例 #1
0
        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))));
        }
コード例 #2
0
        /// <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))));
        }