InkCanvas 上的 MouseLeftButtonDown 事件

发布于 2025-01-04 22:24:05 字数 779 浏览 3 评论 0原文

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

Hi I have no ide why it isn't work. It looks like I can't use this event on 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>

Code Behind

private void MC_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    polylinePoints.Add(e.GetPosition(MC));
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抚笙 2025-01-11 22:24:05

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

Apparently the InkCanvas handles the MouseLeftButtonDown event internally to initiate the drawing of an ink stroke. You could instead use the PreviewMouseLeftButtonDown event, but you should be careful with what you do. In an InkCanvas a user would usually expect to start drawing a stroke when he presses the left mouse button.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文