如何在图像MouseDown上提示窗口

时间:2013-10-28 18:34:13

标签: wpf image prompt inkcanvas tablet-pc

我正在创建一个应用程序(用于平板电脑),用户将在其中填写检查表。作为最后一步,导演必须能够签名(与其他一些人一起)。

由于我想让我的表单小巧简洁,我想在图像控件上创建一个点击事件,它会弹出我的签名画布窗口。​​

我的图像控件的XAML代码

...
<DockPanel HorizontalAlignment="Stretch" Name="dpDirectorImg" VerticalAlignment="Stretch" Grid.Column="1" Grid.Row="8">
   <Image Height="Auto" Name="imgDirectorSignature" Stretch="Uniform" Width="Auto" MouseDown="imgDirectorSignature_MouseDown" />             
</DockPanel>
...

VB代码

Private Sub imgDirectorSignature_MouseDown(sender As Object, e As System.Windows.Input.MouseButtonEventArgs) Handles imgDirectorSignature.MouseDown
    MsgBox("Hello World")
End Sub

例如,在下面的屏幕截图中,用户将触摸/单击红色矩形(其中包含一个Image控件):

Signature location

会提示此窗口:

Signature window

我的问题:我似乎无法触发Image上的事件。我尝试过TouchDown,MouseDown,StylusDown,GotFocus(将属性Focasable设置为true),似乎什么也没有触发它。

1 个答案:

答案 0 :(得分:1)

现在我们发现了问题所在。

如何停止使用空图像,而不是使用矩形:

<DockPanel HorizontalAlignment="Stretch" Name="dpDirectorImg" VerticalAlignment="Stretch" Grid.Column="1" Grid.Row="8">
   <Rectangle MouseDown="imgDirectorSignature_MouseDown" />             
</DockPanel>

如果矩形默认有任何背景颜色,您可以将其更改为透明

Background = Transparent

很高兴我能够帮助你解决这个问题,并注意到,当Image的背景或来源为NULL时,wpf中的命中测试将无效。这是设计的。

将背景设置为透明或您喜欢的任何颜色:)