In order to apply a triggered animation to all ToolTips in my app, I’m using a ControlTemplate. However, when using a ControlTemplate the ToolTip loses all of its default visual properties as defined, I believe, by the theme. How can I retain all properties except for those that I override?
Using the following code
<ToolTip Opacity="0.8">
<ToolTip.Content>
<StackPanel>
<Label FontWeight="Bold" Background="DarkSlateBlue" Foreground="White">
WpfApplication1
</Label>
<Label>
Click to create another button
</Label>
</StackPanel>
</ToolTip.Content>
</ToolTip>
I get the result I want:
alt text http://img29.imageshack.us/img29/1488/controltemplateno.png
But when I adjust the code to use a ControlTemplate as so:
<ControlTemplate x:Key="controltemplateToolTip" TargetType="{x:Type ToolTip}">
<ContentPresenter Content="{TemplateBinding Content}" />
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="ToolTip.Loaded">
<BeginStoryboard>
<Storyboard TargetProperty="Opacity">
<DoubleAnimation From="0" To="0.8" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style TargetType="{x:Type ToolTip}">
<Setter Property="Template" Value="{StaticResource controltemplateToolTip}" />
</Style>
...
<ToolTip>
<ToolTip.Content>
<StackPanel>
<Label FontWeight="Bold" Background="DarkSlateBlue" Foreground="White">
WpfApplication1
</Label>
<Label>
Click to create another button
</Label>
</StackPanel>
</ToolTip.Content>
</ToolTip>
I get the following:
alt text http://img43.imageshack.us/img43/8217/controltemplateyes.png
As you can see, the theme default border, background, etc. are not maintained. I don’t want to set these explicitly as I want them to adjust according to the user’s theme. How can I remedy this? Am I going about this the wrong way?
You can’t inherit ControlTemplate from theme style. But you don’t have to. Use DataTemplates to achieve what you want. Here is a quick example:
You can paste it to Kaxaml, and test it.
Hope this helps.