コード例 #1
0
        public void AddDemoProperty(DependencyPropertyDescriptor descriptor, FrameworkElement bindingTarget)
        {
            if (descriptor.IsReadOnly || descriptor.DesignTimeOnly || !descriptor.IsBrowsable)
            {
                return;
            }

            var demoProperty = new DemoProperty(descriptor);

            DemoProperties.Add(demoProperty);

            try
            {
                demoProperty.Value = bindingTarget.GetValue(descriptor.DependencyProperty);

                var binding = new Binding(nameof(DemoProperty.Value))
                {
                    Source = demoProperty,
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                };

                bindingTarget.SetBinding(descriptor.DependencyProperty, binding);
            }
            catch (Exception e)
            {
                Debug.WriteLine($"{e.Message} ({e.Source}");
            }
        }
コード例 #2
0
        public void AddDemoProperty(DependencyProperty dependencyProperty, DependencyObject bindingTarget, string groupName = null, DataTemplate template = null, object MinValue = null, object MaxValue = null)
        {
            if (dependencyProperty is null)
            {
                throw new ArgumentNullException(nameof(dependencyProperty));
            }

            var property = new DemoProperty()
            {
                GroupName     = groupName ?? GetGroupName(dependencyProperty.Name),
                PropertyName  = dependencyProperty.Name,
                MinValue      = MinValue,
                MaxValue      = MaxValue,
                ValueTemplate = template ?? GetBuildInTemplate(dependencyProperty.PropertyType)
            };

            var binding = new Binding(dependencyProperty.Name)
            {
                Source = bindingTarget,
                Mode   = BindingMode.TwoWay
            };

            BindingOperations.SetBinding(property, DemoProperty.ValueProperty, binding);

            DemoProperties.Add(property);
        }