ispiro ispiro - 1 month ago 6
C# Question

How to get the value of an attached property in code?

I have a button with a

ToolTipService.ToolTip
in it.
How do I access it in code?

e.g.

<Button Name="testButton">
<ToolTipService.ToolTip>
Test
</ToolTipService.ToolTip>
</Button>

Answer

To get the value of an attached property, use the provided static method:

var tooltip = ToolTipService.GetToolTip(testButton);

If there is no such static method (not likely, all classes should have static helper methods to get/set attached properties they expose), then use:

var tooltip = testButton.GetValue(ToolTipService.ToolTipProperty);