locked
Setting ToolTip duration in a Style RRS feed

  • Question

  • So I have a xaml Style set up for ToolTips in my application.  Great!  I have some lengthy ToolTips throughout the program, so I'd like to increase the default duration of 5 seconds to 30.  The ToolTipService seems to be responsible for this through the ShowDuration property, but every example I can find seems to work by setting this value for each individual ToolTip.  There are probably hundreds of ToolTips in my app, so that would be painful to set manually for each one.  Is it possible to set the ShowDuration value in my ToolTip style?  I tried this simple approach...

    <Setter Property="ToolTipService.ShowDuration" Value="30000" />
    But to no avail.  ToolTips still only show for 5 seconds.

    Thanks!
    Tuesday, July 7, 2009 9:46 PM

Answers

  • Hello Thalandor46,

       ToolTipService.ShowDuration attached property is set on the Element which has the ToolTip

       If we set the attached property on the ToolTip itself, it doesn't work.

       We can set it on the style which is applied on the Element.

       Here is an example (element is a Button):
            <Grid.Resources>
                <Style TargetType="Button">
                    <Setter Property="ToolTipService.ShowDuration" Value="1000">
    
                    </Setter>
                </Style>
            </Grid.Resources>
            
            <Grid.ColumnDefinitions>
                <ColumnDefinition>
                    
                </ColumnDefinition>
                <ColumnDefinition>
                    
                </ColumnDefinition>
            </Grid.ColumnDefinitions>
            
            <StackPanel Grid.Column="0">
                <StackPanel.Resources>
                    <Style TargetType="Button">
                        <Setter Property="ToolTipService.ShowDuration" Value="30000">
                            
                        </Setter>
                    </Style>
                </StackPanel.Resources>
                <Button Height="20">
                    <Button.ToolTip>
                        <TextBlock>
                            ToolTip has show duration of 30 seconds. It is from Stack Resource.
                        </TextBlock>
                    </Button.ToolTip>
                </Button>
            </StackPanel>
            <StackPanel Grid.Column="1">
                <Button Height="20">
                    <Button.ToolTip>
                        <TextBlock>
                            ToolTip has show duration of 1 seconds. It is from Grid Resource.
                        </TextBlock>
                    </Button.ToolTip>
                 
                </Button>
            </StackPanel>
        </Grid>
        Thanks.


    Please mark the replies as answers if they help and unmark them if they provide no help
    • Marked as answer by Hua Chen Wednesday, July 15, 2009 6:00 AM
    Tuesday, July 14, 2009 6:28 AM

All replies

  • You can make a Style for the entire type:

    <Style TargetType="ToolTip">
        <Setter Property="ToolTipService.ShowDuration" Value="30000" />
    </Style>


    http://weblogs.asp.net/marianor/
    Tuesday, July 7, 2009 9:51 PM
  • Sorry, seems I wasn't clear.  The general ToolTip style is already in place.  What I was trying to say I had with that Setter was more along these lines:

    <Style TargetType="{x:Type ToolTip}">
       [Other Property Setters]
       <Setter Property="ToolTipService.ShowDuration" Value="30000" />
       <Setter Property="Template">
          <Setter.Value>
             <ControlTemplate TargetType="{x:Type ToolTip}">
                [Template]
             </ControlTemplate>
          </Setter.Value>
        </Setter>
    </Style>


    Adding the Setter for the ShowDuration property didn't work.  The ToolTip duration remains unchanged.  All other ToolTip properties in the Style can be set just fine and are applied properly.  I also tried setting the value at the Window level, and that also didn't work.

    Any other ideas?
    Tuesday, July 7, 2009 10:45 PM
  • Hello Thalandor46,

       ToolTipService.ShowDuration attached property is set on the Element which has the ToolTip

       If we set the attached property on the ToolTip itself, it doesn't work.

       We can set it on the style which is applied on the Element.

       Here is an example (element is a Button):
            <Grid.Resources>
                <Style TargetType="Button">
                    <Setter Property="ToolTipService.ShowDuration" Value="1000">
    
                    </Setter>
                </Style>
            </Grid.Resources>
            
            <Grid.ColumnDefinitions>
                <ColumnDefinition>
                    
                </ColumnDefinition>
                <ColumnDefinition>
                    
                </ColumnDefinition>
            </Grid.ColumnDefinitions>
            
            <StackPanel Grid.Column="0">
                <StackPanel.Resources>
                    <Style TargetType="Button">
                        <Setter Property="ToolTipService.ShowDuration" Value="30000">
                            
                        </Setter>
                    </Style>
                </StackPanel.Resources>
                <Button Height="20">
                    <Button.ToolTip>
                        <TextBlock>
                            ToolTip has show duration of 30 seconds. It is from Stack Resource.
                        </TextBlock>
                    </Button.ToolTip>
                </Button>
            </StackPanel>
            <StackPanel Grid.Column="1">
                <Button Height="20">
                    <Button.ToolTip>
                        <TextBlock>
                            ToolTip has show duration of 1 seconds. It is from Grid Resource.
                        </TextBlock>
                    </Button.ToolTip>
                 
                </Button>
            </StackPanel>
        </Grid>
        Thanks.


    Please mark the replies as answers if they help and unmark them if they provide no help
    • Marked as answer by Hua Chen Wednesday, July 15, 2009 6:00 AM
    Tuesday, July 14, 2009 6:28 AM
  • <Style TargetType="ToolTip">
        <Setter Property="ToolTipService.ShowDuration" Value="30000" />
    </Style>
    • Proposed as answer by dayanandavt Tuesday, July 14, 2009 9:44 AM
    • Unproposed as answer by Hua Chen Wednesday, July 15, 2009 5:59 AM
    Tuesday, July 14, 2009 9:44 AM
  • Hello dayanandavt,

      Sorry It doesn't work while setting on the ToolTip.

     Thanks.
    Please mark the replies as answers if they help and unmark them if they provide no help
    Wednesday, July 15, 2009 6:00 AM