RegisterAttached() public static method

public static RegisterAttached ( string name, Type propertyType, Type ownerType ) : DependencyProperty
name string
propertyType Type
ownerType Type
return DependencyProperty
示例#1
0
        public static void RegisterForNotification([NotNull] this FrameworkElement element, string PropertyName, PropertyChangedCallback callback)
        {
            var binding = new Binding(PropertyName)
            {
                Source = element
            };
            var prop = DependencyProperty.RegisterAttached($"ListenAttached{PropertyName}",
                                                           typeof(object),
                                                           element.GetType(),
                                                           new PropertyMetadata(callback));

            element.SetBinding(prop, binding);
        }
示例#2
0
        public static DependencyProperty RegisterListener(
            string propertyPath,
            Type type,
            PropertyChangedCallback callback)
        {
            long   index    = DateTime.Now.Ticks;
            string typeName = type.Name.Replace('.', '_');
            string name     = string.Format("Listener{0}{1}{2}",
                                            typeName,
                                            propertyPath,
                                            index);

            DependencyProperty prop = null;

            do
            {
                try
                {
                    prop = DependencyProperty.RegisterAttached(
                        name,
                        typeof(object),
                        type,
                        new PropertyMetadata(callback));
                    break;
                }
                catch
                {
                    index = DateTime.Now.Ticks;
                    name  = string.Format("Listener{0}{1}{2}",
                                          typeName,
                                          propertyPath,
                                          index);
                }
            }while (true);

            return(prop);
        }