Question

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}" />  
Was it helpful?

Solution

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>

OTHER TIPS

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>

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top