ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What is the difference between CLR property and Dependency Property in WPF ?

user-image
تم إضافة السؤال من قبل Abhijeet Saxena , Software Engineering Analyst , Accenture Services Pvt. Ltd
تاريخ النشر: 2016/09/04
Amit Sharma
من قبل Amit Sharma , Systems Analyst , TCS

CLR property is just a wrapper around private variables. It uses Get / Set methods to retrieve and store value of a variable into it. A CLR property gives you only one block in which you can write code to invoke whenever a property is get or set.

Dependency Property it is not stored in a field of your object, but in a dictionary of keys and values provided by the base class Dependency Object. The key of an entry is the name of the property and the value is the value you want to set.

WPF has provided some extended services to the CLR property that we can collectively call Dependency Properties. A Dependency Property is a property whose value depends on the external sources, such as animation, data binding, styles, or visual tree inheritance. Not only this, but a Dependency Property also has the built-in feature of providing notification when the property has changed, data binding and styling.

To work with dependency property, you must derive your class from Dependency Object as the whole observer which holds the new Property System is defined within the Dependency Object.

E.g.

public static readonly DependencyProperty TestProperty =

DependencyProperty.Register("Test", typeof(string), typeof(Window1));

public string Test

{

    get

    {

        return this.GetValue(TestProperty) as string;

    }

    set

    {

        this.SetValue(MyCustomProperty, value);

    }

}

Ajay kumar
من قبل Ajay kumar

Whereas when you set a value of a Dependency Property it is not stored in a field of your object, but in a dictionary of keys and values provided by the base class DependencyObject. The key of an entry is the name of the property and the value is the value you want to set

المزيد من الأسئلة المماثلة