视觉特性,以便在我的应用程序触发动画应用到所有ToolTip
S,我使用的是ControlTemplate
。然而,使用ControlTemplate
的ToolTip
时失去其所有的默认视觉特性的定义,我相信,通过主题。我如何保留除我重写的所有属性?保持默认与控件模板
使用下面的代码
<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>
我得到的结果,我想:
alt text http://img29.imageshack.us/img29/1488/controltemplateno.png
但是,当我调整代码使用ControlTemplate
像这样:
<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>
我收到以下内容:
alt text http://img43.imageshack.us/img43/8217/controltemplateyes.png
正如你所看到的,主题默认边框,背景等不保留。我不想明确地设置这些,因为我希望它们根据用户的主题进行调整。我该如何补救?我是否以这种错误的方式去做?
另外请注意,在'ToolTip'风格中添加'BasedOn =“{StaticResource {x:Type ToolTip}}'没有帮助 – Gregyski 2009-08-27 20:07:54