Add Attach Property to Existing Control

一曲冷凌霜 提交于 2019-12-11 14:09:21

问题


I want to add a Property such as 'Description' to Button control, that i use it in Tooltip. how can i add a property to a control?


回答1:


Attached properties are not added to any specific control.

Attached properties are defined in static class, and can be used with any UI control.

Refer to this link to for walkthrough to Add custom attached property.

You can Bind ToolTipService to display tooltip. You need to bind it to Description attached property.

If you want to put property in only one control (so that other controls cannot use it), you need to extend the control, and define Dependency property in it.




回答2:


You can use the Tag propery on the button, that is of the type Object and you can store a description text in it if you like.




回答3:


Create a new control which inherits from the existing one.



来源:https://stackoverflow.com/questions/11382323/add-attach-property-to-existing-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!