InkCanvas上的MouseLeftButtonDown事件

时间:2012-02-14 07:36:58

标签: c# wpf inkcanvas

嗨,我不知道为什么它不起作用。看起来我无法在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));
}

1 个答案:

答案 0 :(得分:5)

显然,InkCanvas在内部处理MouseLeftButtonDown事件以启动墨迹笔划的绘制。您可以改为使用PreviewMouseLeftButtonDown事件,但是您应该小心操作。在InkCanvas中,用户通常希望在按下鼠标左键时开始绘制笔划。