[英]Expose properties of a nested user control
I have a custom usercontrol created by myself which belongs to mine baseControls elements. 我有一个自己创建的自定义用户控件,它属于我的baseControls元素。 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".
在最后一种情况下,我将有一个包含“我的按钮”的userControl“ WRAPPER”。 I need to reveal some properties (dependency properties) of the BUTTON at the WRAPPER level (ie ButtonStatus, Text, etc).
我需要在WRAPPER级别上显示按钮的某些属性(依赖属性)(即ButtonStatus,Text等)。 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...
它包含了WRAPPER级别的属性的某种重复...
Any Hints about this issue !??! 有关此问题的任何提示! Thanks in advance Paolo
在此先感谢Paolo
Here is another StackOverflow thread that shows a solution on how to expose the inner element dependency properties. 这是另一个StackOverflow线程 ,显示了有关如何公开内部元素依赖项属性的解决方案。 Basically, you add the the dependency property to the WRAPPER and bind the BUTTON property to the wrapper property.
基本上,将依赖项属性添加到WRAPPER并将BUTTON属性绑定到wrapper属性。 If the value flow is always from WRAPPER to BUTTON, you can use TemplateBinding instead of Binding.
如果值流始终从WRAPPER到BUTTON,则可以使用TemplateBinding而不是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. 另一种解决方案是研究使用附加属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.