tags:

views:

559

answers:

1

Is there a way to apply a style just to some tooltips? I'm trying to specify tooltip template just for tooltips showing validation erros. Suppose I have a tooltip style, say errorTTStyle, and some validation template:

<Style TargetType="{x:Type TextBox}">
 <Style.Triggers>
  <Trigger Property="Validation.HasError" Value="true">
    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors).CurrentItem.ErrorContent}" />
  </Trigger>
 </Style.Triggers>
</Style>

How to force WPF to use errorTTStyle just for this situation (I know I can change tootlip style globaly, but that's not what I want)?

A: 

You could add the style for the toolTip in the resources of the Textbox style and it would only be used by the parent style, also base that style in the errorTTStyle if you want to use an external style:

<Style TargetType="{x:Type TextBox}">

   <Style.Resources>
        <Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource errorTTStyle}" />
   </Style.Resources>      

<Style.Triggers>
    <Trigger Property="Validation.HasError" Value="true">
      <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors).CurrentItem.ErrorContent}" />
    </Trigger>
  </Style.Triggers>
</Style>
gcores