Difference between Dependency Property and Normal Property

budding_developer 156 Reputation points

Hi, we are able to bind both normal property and dependency property of a usercontrol from another page/usercontrol in WinUI 3. What is the actual difference between dependency properties and normal properties other than PropertyChangedCallback. Which will be better in the performance aspect?

Sample code:

Binding UserControl properties from Window:

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">  
        <local:UserControl1 NormalPropertyText="Normal Text" DependencyPropertyText="Dependency Property Text"/>  

UserControl with Dependency property and Normal property:

public sealed partial class UserControl1 : UserControl  
        public UserControl1()  
        public string NormalPropertyText { get; set; }  
        public string DependencyPropertyText  
            get { return (string)GetValue(DP); }  
            set { SetValue(DP, value); }  
        public static readonly DependencyProperty DP = DependencyProperty.Register(nameof(DependencyPropertyText), typeof(string), typeof(UserControl1), new PropertyMetadata(null));  

Thanks in Advance :)

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
731 questions
0 comments No comments
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 11,581 Reputation points Microsoft Vendor

    See When to implement a property as a dependency property,
    You might consider implementing your property as a dependency property when you want it to support one or more of these features of the Windows Runtime or of Windows Runtime apps:
    It's preferred to use dependency properties with Windows Runtime features but normal properties behave as a language feature.

0 additional answers

Sort by: Most helpful