Windows Phone C#删除最后一个画布行

时间:2014-09-29 03:51:43

标签: c# windows-phone-8 canvas

您好我试图删除在Canvas上输入的最后一行但我只能删除它的某些内容这是我的代码...

if (this.ContentPanelCanvas.Children.Count > 0)
        { this.ContentPanelCanvas.Children.RemoveAt(this.ContentPanelCanvas.Children.Count - 1) ;

...或

IEnumerable<Line> linesOne = ContentPanelCanvas.Children.OfType<Line>();
        if (linesOne.Count() >= 5) { 
        this.ContentPanelCanvas.Children.RemoveAt(linesOne.Count() - 5);
        }

仅删除部分内容而非最后输入的完整行 绘制线代码......

currentPoint = e.GetPosition(this.ContentPanelCanvas) ;
            Line line = new Line() { X1 = currentPoint.X, Y1 = 
            currentPoint.Y, X2 =        oldPoint.X,     Y2 = oldPoint.Y } ;

            line.Stroke = new SolidColorBrush(Colors.Black ) ;
            line.StrokeThickness = SliderOne.Value ;
            line.StrokeStartLineCap = PenLineCap.Round ;
            line.StrokeEndLineCap = PenLineCap.Round ;
            this.ContentPanelCanvas.Children.Add(line) ;
            oldPoint = currentPoint ;

有人可以帮助我...... 感谢

1 个答案:

答案 0 :(得分:0)

用这个

UIElement line=this.canvas.Children[this.canvas.Children.Count-1]; this.canvas.Children.Remove(line);

您可以删除Children集合中的最后一个元素。