【发布时间】:2009-08-26 21:50:57
【问题描述】:
为了将触发动画应用到我的应用程序中的所有ToolTips,我使用了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
如您所见,主题默认边框、背景等都没有维护。我不想明确设置这些,因为我希望它们根据用户的主题进行调整。我该如何补救?我是不是走错了路?
【问题讨论】:
-
另请注意,将
BasedOn="{StaticResource {x:Type ToolTip}}添加到ToolTip样式没有帮助。
标签: .net wpf xaml controltemplate