Harry Boy
Harry Boy

Reputation: 4747

Display button tooltip on a label for wpf button

I have several WPF buttons on my Page and I want to display tooltips when the mouse is hovered over them. But I want the tooltip to appear in a label that I have pplaced on my page so I want to show this label and set its text to something. Whenever the mouse is moved away from the button I want the label to disappear again.

I can change the image of my buton by doin what I learned here: http://www.canofcode.co.uk/software/wpf-rollover-images/ but I cant figure out how to display this tooltip yet....

Upvotes: 0

Views: 1435

Answers (1)

Rohit Vats
Rohit Vats

Reputation: 81243

You can achieve that using DataTrigger on IsMouseOver property of button. This is what you are looking for i guess -

<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
   <Button x:Name="button1" Content="TestButton" Width="100" Height="50"/>
   <Label x:Name="label1" Content="Tooltip Text">
      <Label.Style>
         <Style TargetType="Label">
            <Setter Property="Visibility" Value="Collapsed"/>
            <Style.Triggers>
               <DataTrigger Binding="{Binding ElementName=button1, 
                                              Path=IsMouseOver}" 
                            Value="True">
                   <Setter Property="Visibility" Value="Visible"/>
               </DataTrigger>
            </Style.Triggers>
         </Style>
      </Label.Style>
    </Label>
</StackPanel>

Upvotes: 1

Related Questions