Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to Override a DependencyProperty?

$
0
0

Hello msdn, 

         How can I override a DependencyProperty, in such a way that,it do not hit the base class's PropertyChanged Callback methods?

Recently I have created a class with a dependency property, I have overrided this dependencyProperty in a descendent class, But when I change the value, It is hitting not only the derived class PropertyChanged callback, But also the base class, How can I avoid it hitting the base class?

Could anyone help me to do this, My code is given below.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication7
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            C c = new C();
            c.HasVlidation = true;
        }
    }
 public class P:Control
    {

        static P()
        {
            HasVlidationProperty =
            DependencyProperty.Register("HasVlidation", typeof(bool), typeof(P), new FrameworkPropertyMetadata(false,changed));
        }
        public static readonly DependencyProperty HasVlidationProperty;
        public bool HasVlidation
        {
            get { return (bool)GetValue(HasVlidationProperty); }
            set { SetValue(HasVlidationProperty, value); }
        }

        // Using a DependencyProperty as the backing store for HasVlidation.  This enables animation, styling, binding, etc...
        

        private static void changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            
        }

        
        public P()
        {
        }
    }

    public class C:P
    {
        static C()
        {
            P.HasVlidationProperty.OverrideMetadata(typeof(C), new FrameworkPropertyMetadata(false, changed));
        }

        private static void changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
           
        }
        public C()
        {

        }
    }


}

Regards

Salam

 


salampv.07


Viewing all articles
Browse latest Browse all 18858


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>