xaml: <Grid x:Name="LayoutRoot"> <Canvas x:Name="print" Background="AliceBlue"> </Canvas> </Grid> 后台代码: private Path path; private PathFigure pf; private bool isMove; public Page1() { InitializeComponent(); this.Loaded +=new RoutedEventHandler(Page1_Loaded); } // Executes when the user navigates to this page. protected override void OnNavigatedTo(NavigationEventArgs e) { } void Page1_Loaded(object sender, RoutedEventArgs e) { this.print.MouseLeftButtonDown +=new MouseButtonEventHandler(print_MouseLeftButtonDown); this.print.MouseLeftButtonUp +=new MouseButtonEventHandler(print_MouseLeftButtonUp); this.print.MouseMove +=new MouseEventHandler(print_MouseMove); } public void print_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { FrameworkElement element = sender as FrameworkElement; element.CaptureMouse(); path = new Path() { Stroke = new SolidColorBrush(Colors.Red), StrokeThickness = 2 }; PathGeometry pg = new PathGeometry(); pf = new PathFigure(); pf.StartPoint = e.GetPosition(print); pg.Figures.Add(pf); path.Data = pg; print.Children.Add(path); isMove = true; } public void print_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { FrameworkElement element = sender as FrameworkElement; element.ReleaseMouseCapture(); isMove = false; } public void print_MouseMove(object sender, MouseEventArgs e) { if (isMove) { LineSegment lg = new LineSegment(); lg.Point = e.GetPosition(print); pf.Segments.Add(lg); } } 发现一个问题,在鼠标的移动的时候线无法马上显示出来,而是在再次点击鼠标的时候才能描绘出来。不知怎么解决。偶然发现在工作区内添加一个文本框显示鼠标的坐标时线就能立马的描绘出来。