Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF ToolTip Style

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}" />  
like image 284
raijan_cv Avatar asked Nov 22 '13 06:11

raijan_cv


3 Answers

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>
like image 199
Suresh Avatar answered Oct 18 '22 06:10

Suresh


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>
like image 23
aDoubleSo Avatar answered Oct 18 '22 06:10

aDoubleSo


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>
like image 35
J R B Avatar answered Oct 18 '22 07:10

J R B