从代码在WPF中绘制点序列的最简单方法 [英] Easiest way to draw a sequence of points in WPF from code

查看:150
本文介绍了从代码在WPF中绘制点序列的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个WPF应用程序,该应用程序可以跟踪鼠标光标的位置,并在MouseMove事件处理程序中更新图像.我最初的想法是创建一个GeometryDrawing,然后为其添加路径,但是我在如何将其连接到代码中苦苦挣扎(尽管Xaml for GeometryDrawings看起来很简单).连接这些内容的最简单方法是-仅用于调试,因此我不关心效率.

I'd like to create a WPF app that traces the location of the mouse cursor, updating the image in the MouseMove event handler. My original thought was to create a GeometryDrawing and then add paths to that but I'm struggling with how to wire this up in code (though the Xaml for GeometryDrawings seems straightforward). What's the easiest way to wire this stuff up - its just for debugging so I'm not concerned about efficiency.

推荐答案

仅使用折线怎么样?

这是xaml:

<Window
    x:Class="CursorLine.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1"
>
    <Canvas x:Name="canvas" Background="#00FFFFFF" MouseMove="Canvas_MouseMove">
        <Polyline x:Name="polyline" Stroke="DarkGreen" StrokeThickness="3"/>
    </Canvas>
</Window>

这是背后的代码:

private void Canvas_MouseMove(object sender, MouseEventArgs e)
{
    polyline.Points.Add(e.GetPosition(canvas));
}

这篇关于从代码在WPF中绘制点序列的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆