我可以在 WPF 中明确显示鼠标单击事件的工具提示吗? [英] Can I explicity show tooltip on Mouse Click event in WPF?
本文介绍了我可以在 WPF 中明确显示鼠标单击事件的工具提示吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当鼠标悬停在帮助图像上时,我会显示工具提示.
I am showing a Tool Tip when Mouse hovers on Help image.
xaml 如下:
<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 ?
请帮忙!!
推荐答案
您可以通过设置 ToolTip.IsOpen 为真.您可以通过在设置 ToolTip 属性时显式构造一个对象来获取对 ToolTip 对象的引用.而不是
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>
写
<Image.ToolTip>
<ToolTip>
<Grid>
...
</Grid>
</ToolTip>
</Image.ToolTip>
然后在您的 MouseUp 处理程序中执行以下操作:
And then in your MouseUp handler do something like:
((ToolTip)((FrameworkElement)sender).ToolTip).IsOpen = true;
这篇关于我可以在 WPF 中明确显示鼠标单击事件的工具提示吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文