12

I am showing a Tool Tip when Mouse hovers on Help image.

The xaml is given below:

 <Image 
     x:Name="HelpImage"
     Width="16"
     Height="16"
     Grid.Row="1"
     Source="..\Images\ToolBar\Help.png"
     Grid.Column="2">
     <Image.ToolTip>
         <Grid
             Background="LightGreen">
             <Grid.RowDefinitions>
                 <RowDefinition />
                 <RowDefinition />
             </Grid.RowDefinitions>
             <StackPanel
                 Background="LightGreen"
                 Height="25"
                 Width="300"
                 Orientation="Horizontal"
                 HorizontalAlignment="Left"
                 VerticalAlignment="Top">
                 <Image
                     VerticalAlignment="Stretch"
                     HorizontalAlignment="Stretch"
                     Width="24"
                     Height="24"
                     Source="/Images/Test.png"
                     Name="image1" />
                 <TextBlock
                     FontFamily="Aharoni"
                     Margin="5"
                     FontSize="20"
                     FontWeight="Bold"
                     Foreground="Black"
                     TextWrapping="Wrap"
                     VerticalAlignment="Top"
                     Height="Auto"
                     HorizontalAlignment="Right"
                     Width="Auto">
                       <Run
                          FontFamily="Calibri"
                          FontSize="14"
                          Foreground="DarkRed"
                          FontWeight="Bold"
                          Text="Bandwidth Base Value" />
                 </TextBlock>
             </StackPanel>
             <TextBlock
                 Grid.Row="1"
                 Background="LightGreen">
                 This is Help  content</TextBlock>
         </Grid>
     </Image.ToolTip>
 </Image>

It shows the Tool Tip when user mouse hovers on the image control. Can I explicity show ToolTip when user clicks on the image ?

Please Help!!

4 Answers 4

14

You can force the tool tip to open by setting ToolTip.IsOpen to true. You can get a reference to the ToolTip object by explicitly constructing one when setting the ToolTip property. Instead of

<Image.ToolTip>
    <Grid>
    ...
    </Grid>
</Image.ToolTip>

write

<Image.ToolTip>
    <ToolTip>
        <Grid>
        ...
        </Grid>
    </ToolTip>
</Image.ToolTip>

And then in your MouseUp handler do something like:

((ToolTip)((FrameworkElement)sender).ToolTip).IsOpen = true;
Sign up to request clarification or add additional context in comments.

4 Comments

Many Thanks for the solution.. It worked for me. But where should I set the IsOpen property to false ? I want to close the tool tip if user click anywhere outside the tool tip.
I have handled UserControl_MouseLeftButtonUp in which I have written ((ToolTip)((FrameworkElement)this.HelpImage).ToolTip).IsOpen = false; But this event executes as soon as I do mouse up on Image control.
@AshishAshu I set IsOpen to false in ToolTip.Closed event.
set ToolTip.IsOpen to false on the Image.MouseLeave event
2

No you can't invoked the tooltip on mouseclick. Instead of using Tooltip, you can use Popup control. Invoke the Popup Control on mouse click.

1 Comment

Thanks for the reply . Can I also show a Popup Control on Mouse Hover same as we show tool tip ?
0
EventManager.RegisterClassHandler(typeof(Window), Mouse.MouseDownEvent, 
                                  new MouseButtonEventHandler((o, args) => 
                                  { 
                                      if (_popup.IsOpen) 
                                          _popup.IsOpen = false; 
                                  }));

Comments

-3

OnClick set visibility of tooltip true and in ToolTipClosing set visibility c

<ToolTip Name="ToolTipGift" ToolTipClosing="ToolTipGift_ToolTipClosing" Visibility="Collapsed">
....
</ToolTip>

1 Comment

Please complete your answer and add a code example to make it more useful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.