lightwalker01
11/24/2017 - 6:36 PM

WPF DependencyProperties

WPF DependencyProperties

        #region Test
        [Description("Custom dependency property"), Category("Custom")]
        public bool Test
        {
            get { return (bool)GetValue(TestProperty); }
            set { SetValue(TestProperty, value); }
        }

        public static readonly DependencyProperty TestProperty =
            DependencyProperty.Register("Test", typeof(bool), typeof(MainWindow), new PropertyMetadata(false, TestChanged));

        private static void TestChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var element = d as FrameworkElement;
            if (element == null)
                return;
        }
        #endregion
        #region Test   
        [Description("Custom attached property"), Category("Custom")]
        [AttachedPropertyBrowsableForType(typeof(FrameworkElement))]
        public static bool GetTest(DependencyObject obj)
        {
            return (bool)obj.GetValue(TestProperty);
        }

        public static void SetTest(DependencyObject obj, bool value)
        {
            obj.SetValue(TestProperty, value);
        }

        public static readonly DependencyProperty TestProperty =
            DependencyProperty.RegisterAttached("Test", typeof(bool), typeof(MainWindow), new PropertyMetadata(false, TestChanged));

        private static void TestChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var element = d as FrameworkElement;
            if (element == null)
                return;
        }
        #endregion