简体   繁体   English

公开嵌套用户控件的属性

[英]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.

相关问题 如何公开用户控件内部的控件的属性? - How to Expose Properties of a Control that is Inside a User Control? 直接公开用户控件的子属性作为用户控件的属性 - Expose child properties of user control directly as property of user control 如何在用户控件中公开自定义控件属性? - How do I expose custom control properties inside a user control? 有没有一种方法可以自动公开包装在用户控件中的标准wpf控件的属性和事件? - Is there a way to automatically expose properties and events of a standard wpf control wrapped in a user control? WPF用户控件的公开属性 - Expose property for WPF user control 如何在自定义控件位于用户控件内的MainWindow.xaml中公开自定义控件的事件和属性? - How do I expose custom control events and properties in MainWindow.xaml where my custom control is inside a User Control? 将WPF控件的属性公开给WinForms主机 - Expose properties of a WPF control to the WinForms host 如何公开嵌套在UserControl中的控件的DependencyProperty? - How to Expose a DependencyProperty of a Control nested in a UserControl? 在WPF用户控件中公开多个命令 - Expose multiple command in WPF user control 在WPF用户控件中公开一个字段以供外部使用 - expose a field in wpf user control for external use
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM