5

Dependent property correct use

 3 years ago
source link: https://www.codesd.com/item/dependent-property-correct-use.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Dependent property correct use

advertisements

i have a wpf control that i'm developing.

this control contains and encapsulate another control.

i want to expose a property of the inner control to the window that consumes the control. i also want the inner control to perform logic when this property changed.

any suggestions?


Both the inner and outer controls should define dependency properties. The template for the outer control should include the inner control, and should bind the properties together:

<local:InnerControl SomePropertyOnInnerControl="{TemplateBinding SomePropertyOnOuterControl}"/>

This ensures both your controls are independently usable and decoupled from eachother. The properties can be named according to their use in that control. For example, the inner control may call it something like Text whilst the outer control uses it for a more specific purpose like CustomerName.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK