Wpf 如何为工具提示设置样式的InitialShowDelay?

Wpf 如何为工具提示设置样式的InitialShowDelay?,wpf,wpf-style,Wpf,Wpf Style,我正在尝试设置工具提示样式的延迟。为此,我使用了一个依赖属性 这是一种风格: <Style TargetType="ToolTip" x:Key="ToolTipDefaultStyle"> <Setter Property="ToolTipService.ShowOnDisabled" Value="true"/> <Setter Property="Tool

我正在尝试设置工具提示样式的延迟。为此,我使用了一个依赖属性

这是一种风格:

<Style TargetType="ToolTip" x:Key="ToolTipDefaultStyle">
    <Setter Property="ToolTipService.ShowOnDisabled" Value="true"/>
    <Setter Property="ToolTipService.InitialShowDelay" Value="{Binding PlacementTarget.(ap:ToolTipAttachedProperty.InitialShowDelay), RelativeSource={RelativeSource AncestorType=ToolTip}}"/>
    <Setter Property="ToolTipService.ShowDuration" Value="{Binding PlacementTarget.(ap:ToolTipAttachedProperty.ShowDuration), RelativeSource={RelativeSource AncestorType=ToolTip}}"/>
    <Setter Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="{Binding PlacementTarget.(ap:ToolTipAttachedProperty.Texto), RelativeSource={RelativeSource AncestorType=ToolTip}}"  MaxWidth="400" TextWrapping='Wrap' />
                </StackPanel>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

这是一种观点:

<StackPanel Name="spTiposIva" Orientation="Vertical" Margin="5,0,0,0"
            ap:ToolTipAttachedProperty.Texto="{Binding TiposIvaTooltip}"
            ap:ToolTipAttachedProperty.InitialShowDelay="10000"
            ap:ToolTipAttachedProperty.ShowDuration="{StaticResource TooltipDisplayTime}">
    <StackPanel.ToolTip>
        <ToolTip Style="{StaticResource ToolTipDefaultStyle}"/>
    </StackPanel.ToolTip>
</StackPanel>

文本显示正确,但初始显示延迟是默认值,不会延迟10秒

我如何设置延迟


谢谢。

其他属性,如禁用的
显示的
也不起作用。这是因为您将附加的
ToolTipService
属性设置在
ToolTip
本身上,或者以针对它的样式设置。相反,您必须在与工具提示关联的控件上设置这些属性,而不是工具提示本身

如果您直接将它们附加到
StackPanel
或以其样式附加,例如:

<StackPanel Name="spTiposIva" Orientation="Vertical" Margin="5,0,0,0"
            ToolTipService.ShowOnDisabled="True"
            ToolTipService.InitialShowDelay="10000"
            ToolTipService.ShowDuration="{StaticResource TooltipDisplayTime}"
            ToolTip="Binding TiposIvaTooltip">
   <!-- ...your content. -->
</StackPanel>
<Style TargetType="{x:Type StackPanel}" x:Key="StackPanelDefaultStyle">
   <Setter Property="ToolTipService.ShowOnDisabled" Value="true"/>
   <Setter Property="ToolTipService.InitialShowDelay" Value="{Binding (ap:ToolTipAttachedProperty.InitialShowDelay), RelativeSource={RelativeSource Self}}"/>
   <Setter Property="ToolTipService.ShowDuration" Value="{Binding (ap:ToolTipAttachedProperty.ShowDuration), RelativeSource={RelativeSource Self}}"/>
</Style>
<Style TargetType="ToolTip" x:Key="ToolTipDefaultStyle">
   <Setter Property="ContentTemplate">
      <Setter.Value>
         <DataTemplate>
            <StackPanel>
               <TextBlock Text="{Binding PlacementTarget.(ap:ToolTipAttachedProperty.Texto), RelativeSource={RelativeSource AncestorType=ToolTip}}"  MaxWidth="400" TextWrapping='Wrap' />
            </StackPanel>
         </DataTemplate>
      </Setter.Value>
   </Setter>
</Style>
<Style TargetType="{x:Type FrameworkElement}" x:Key="FrameworkElementDefaultStyle">