我想添加選項以在圖像上繪製矩形。但這不是問題。 爲了讓它工作,我需要使用WPF中Image Control的MouseDown,MouseUp和MouseLeave事件。MouseDown event not fireing
<DockPanel Name="dockPanel1" Grid.ColumnSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="15">
<GroupBox Header="WebCam" Name="groupBox1" VerticalAlignment="Top" HorizontalAlignment="Left">
<Grid>
<Image HorizontalAlignment="Left" Margin="0" Name="pictureBoxMain" Stretch="Fill" VerticalAlignment="Top" MinHeight="240" MinWidth="320" StretchDirection="DownOnly" MaxWidth="960" MaxHeight="1200" MouseDown="pictureBoxMain_MouseDown" MouseUp="pictureBoxMain_MouseUp" MouseLeave="pictureBoxMain_MouseLeave" Panel.ZIndex="50" />
</Grid>
</GroupBox>
<StackPanel HorizontalAlignment="Right" Name="stackPanel2" VerticalAlignment="Top" DockPanel.Dock="Right" Margin="15,0,0,0">
<GroupBox Header="Controls" Name="groupBox2">
<StackPanel Name="stackPanel1">
<Button Content="Start" Height="23" Name="buttonStartStop" Width="120" Margin="0" Click="buttonStartStop_Click" />
<Button Content="Video Properties" Height="23" Name="buttonVideoProperties" Width="120" Margin="0" Click="buttonVideoProperties_Click" />
<Button Content="WebCam Settings" Height="23" Name="buttonWebCamSettings" Width="120" Margin="0" Click="buttonWebCamSettings_Click" />
</StackPanel>
</GroupBox>
<GroupBox Header="Motion Data" Name="groupBox3">
<StackPanel>
<Label Content="Strength: 0" x:Name="labelMotionStrength" />
<Label Content="Count: 0" x:Name="timesWasMotionCounter" />
</StackPanel>
</GroupBox>
</StackPanel>
</DockPanel>
我在說「pictureBoxMain」的事件。 爲什麼這些事件永遠不會開火?我像瘋了一樣點擊我的圖片,但仍然沒有。 我應該怎麼做才能使這些活動起作用?
嘗試處理PreviewMouseDown來代替(http://stackoverflow.com/questions/2858539/image-mousedown-event-not-firing) – Surfbutler
@Surfbutler仍然無法正常工作。 – Hooch
嘗試將鼠標處理程序放在父網格上,併爲網格指定「透明」的背景屬性。 –