简体   繁体   中英

Expose properties of a nested user control

I have a custom usercontrol created by myself which belongs to mine baseControls elements. It's a special button which have some animations and other cool features. It will be used stand alone in some applications, and wrapped into containers in other applications. In the last case I will have an userControl "WRAPPER" that will contain my "BUTTON". I need to reveal some properties (dependency properties) of the BUTTON at the WRAPPER level (ie ButtonStatus, Text, etc). A sort of tunneling of properties. I googled a little bit and I found an interesting solution at this link: Exposing Bindings as Properties of a Control but I don't know if its be best solution or if it's the only one! It consist in a sort of duplication of the properties at WRAPPER level...

Any Hints about this issue !??! Thanks in advance Paolo

Here is another StackOverflow thread that shows a solution on how to expose the inner element dependency properties. Basically, you add the the dependency property to the WRAPPER and bind the BUTTON property to the wrapper property. If the value flow is always from WRAPPER to BUTTON, you can use TemplateBinding instead of Binding.

One solution is, as you suggest, adding properties to the wrapper that mirror (and are bound to) the underlying properties you want to expose.

The other solution is to look into using attached properties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM