Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

wpf controls - Can I explicity show tooltip on Mouse Click event in WPF?

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="..ImagesToolBarHelp.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!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...