ispiro
ispiro

Reputation: 27673

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>

Upvotes: 2

Views: 2451

Answers (1)

Decade Moon
Decade Moon

Reputation: 34286

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);

Upvotes: 7

Related Questions