Bill Henning

Hi all,

As an example of my issue, say I wanted to specify an attached ToolTipService.ToolTip property value on a class that doesn't natively have a ToolTip property and I need the value of the property to be an object... like a complex StackPanel of controls.

Normally attached properties are specified as attributes using the inline DeclaringTypeName.PropertyName syntax. But can they be specified using expanded syntax somehow that allows object values Something like this although this doesn't work:

<test:MyClass>

<ToolTipService.ToolTip>

<StackPanel>

...

</StackPanel>

</ToolTipService.ToolTip>

</test:MyClass>

Thanks in advance!




Re: Windows Presentation Foundation (WPF) How to specify an attached property value in XAML using expanded syntax

Charles Petzold

Normally this syntax would be OK, but I don't think you can't use ToolTipService to add ToolTip functionality to a class that doesn't already have a ToolTip property.

How can MyClass not have a ToolTip property Doesn't it derive from FrameworkElement





Re: Windows Presentation Foundation (WPF) How to specify an attached property value in XAML using expanded syntax

Charles Petzold

Sorry for the double negative. It should be "but you can't use...."





Re: Windows Presentation Foundation (WPF) How to specify an attached property value in XAML using expanded syntax

Drew Marsh

Is "MyClass" a sublcass of DependencyObject Only DependencyObject subclasses can have properties attached to them.

HTH,
Drew





Re: Windows Presentation Foundation (WPF) How to specify an attached property value in XAML using expanded syntax

Bill Henning

Sorry guys I should have been more clear. My scenario with this issue is for a custom class with a custom attached property that I've defined. I just gave the tooltip sample since it is an attached property that people know but the concept is the same as the issue I have with my own custom attached property.

So assume that MyClass inherits DependencyObject (but not FrameworkElement) and I want to set the ToolTip property on it (again, just as a sample of the syntax). And I also don't want to define a ToolTip dependency property on MyClass since in this scenario we have to assume I don't have access to the MyClass source code.

To set a simple ToolTip value inline I would do this:

<test:MyClass ToolTipService.ToolTip="My tooltip value" />

However as I posted above, I need to be able to set a complex type such as a StackPanel, not just a simple string like "My tooltip value". And I've been unable to find the expanded syntax for doing so with an attached property.

I hope that clarifies a little better what I'm trying to accomplish.






Re: Windows Presentation Foundation (WPF) How to specify an attached property value in XAML using expanded syntax

Drew Marsh

Gotcha. The expanded syntax is pretty simple:

Code Block

<test:MyClass>

<ToolTipService.ToolTip>

<!-- complex type here -->

</ToolTipService.ToolTip>

</test:MyClass>

HTH,
Drew





Re: Windows Presentation Foundation (WPF) How to specify an attached property value in XAML using expanded syntax

Bill Henning

I originally tried something like that (at least I thought that's what I entered) but I must have mistyped it. I just tried it again and it worked perfectly. My bad! Thanks Drew.