WPF ToolTip Style
Asked Answered
C

3

12

I have one ToggleButton with ToolTip, content of ToolTip is bind with Text property. Now I need to style my ToolTip within ToggleButton. I know its not allow me apply style within ToggleButton for ToolTip and I don't know how to do it.

Here is what my code looks like:

<ToggleButton
    x:Name="btn"
    Margin="10,0,0,20"
    Style="{StaticResource bubbleStyle}"
    ToolTip="{Binding ElementName=tbText, Path=Text, Mode=TwoWay}" />  
Cristacristabel answered 22/11, 2013 at 6:32 Comment(0)
G
18

If I understand your question correctly, you want to define a style for ToolTip within your ToggleButton.

Try this:

<ToggleButton Content="ON" Grid.Row="1" ToolTip="{Binding ElementName=tbText, Path=Text}">
    <ToggleButton.Resources>
        <Style TargetType="ToolTip" BasedOn="{StaticResource {x:Type ToolTip}}">
            <Setter Property="Background" Value="Red" />
        </Style>
    </ToggleButton.Resources>
</ToggleButton>
Gyration answered 22/11, 2013 at 7:16 Comment(1)
Thanks for this so much, I couldn't find the right syntax anywhere. We had created a global ToolTip style and it was overriding another very important ToolTip style so I added a key to the new one and applied it using this technique, Thanks!!Daisydaitzman
H
9

You have to declare the style and all tooltips of your control will be shown in this style.

<Window.Resources>
  <Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
      <Setter Property="OverridesDefaultStyle" Value="true" />
      <Setter Property="HasDropShadow" Value="True" />
      <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ToolTip">
              <!-- define your control template -->
            </ControlTemplate>
        </Setter.Value>
      </Setter>
  </Style>
<Window.Resources>
Haworth answered 22/11, 2013 at 7:7 Comment(0)
C
2

You can set style inline or can create in windows resources with Type. in Type you have to assign ToggleButton .

Inline-

  <ToggleButton  >
   <ToggleButton.ToolTip>
    <ToolTip>
        <StackPanel>
            <TextBlock FontWeight="Bold">TEXT HERE</TextBlock>
            <TextBlock>SECOND TEXT HERE.</TextBlock>
        </StackPanel>
    </ToolTip>
</ToggleButton.ToolTip>

In Window Resource (as describe by @aDoubleSo)

<Window.Resources>
  <Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
  <Setter Property="OverridesDefaultStyle" Value="true" />
  <Setter Property="HasDropShadow" Value="True" />
 </Style>
<Window.Resources>
Cotquean answered 22/11, 2013 at 7:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.