Dependency properties, simply stated, the properties that can be referenced directly on the interface during the WPF control application process
such as: <button content= "AAA" ></Button>
Content is called a dependency property of a button
How do we add dependency properties when we customize the control?
1. Adding attributes
/// <summary> /// get or set the items /// </summary> Public List<titlelistitemmodel> titlelistitems { get { return (list<titlelistitemmodel>) GetValue (titlelistitemsproperty) } Set {SetValue (titlelistitemsproperty,value);}; }
2. Registration Properties
Public Static ReadOnly DependencyProperty Titlelistitemsproperty = Dependencyproperty.register ("titlelistitems" typeof(list<titlelistitemmodel>), typeof(Titlelistcontrol), New PropertyMetadata (new list<titlelistitemmodel> ()));
You can then set properties directly when you apply a custom control, for example:
The Titlelistitems property can be added directly to the interface
<wpfapplication6:titlelistcontrol verticalalignment="Center"> <wpfApplication6:TitleListControl.TitleListItems> <wpfapplication6:titlelistitemmo Del name="AAA"text="AA"></wpfApplication6:TitleListItemModel> <wpfapplication6:titlelistitemmodel name="BB"text="BB"></wpfApplication6:TitleListItemModel> <wpfapplication6:titlelistitemmodel name="CCC"text="CC"></wpfApplication6:TitleListItemModel> </wpfApplication6:TitleListControl.TitleListItems> </wpfApplication6:TitleListControl>
WPF Dependency Properties