WPF Dependency Properties

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.