嗨,我不知道为什么它不起作用。看来我无法在InkCanvas上使用此事件。
XAML
<Window x:Class="PolyLine.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel >
<Button Name="Button1">Clear</Button>
<InkCanvas x:Name="MC" MouseLeftButtonDown="MC_MouseLeftButtonDown" MouseRightButtonDown="MC_MouseRightButtonDown" MouseMove="MC_MouseMove" Background="White" Height="300" Width="497" ></InkCanvas>
</StackPanel>
背后的代码
private void MC_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
polylinePoints.Add(e.GetPosition(MC));
}
最佳答案
显然,InkCanvas在内部处理MouseLeftButtonDown事件以启动墨水笔划的绘制。您可以改用PreviewMouseLeftButtonDown事件,但是在执行操作时要小心。在InkCanvas中,用户通常希望在按下鼠标左键时开始绘制笔画。