uwp如何删除一行
uwp how to delete a line
public void CreateALine(double x1, double y1)
{
// Create a Line
Line redLine = new Line();
redLine.X1 = x + 20;
redLine.Y1 = y + 20;
redLine.X2 = x1 + 20;
redLine.Y2 = y1 + 20;
SolidColorBrush gBrush = new SolidColorBrush();
gBrush.Color = Colors.Green;
redLine.StrokeThickness = 2;
redLine.Stroke = gBrush;
// Add line to the Canvas
canvas2.Children.Add(redLine);
}
这是我的代码,现在我想删除这一行,谁能告诉我该怎么做?
谢谢。
Children property is nothing more than a UIElementCollection object attached to the Canvas control.
UIElementCollection
对象有一些方法可以让您从自身删除对象,这可能因编程语言而异。
对于您的情况,Remove and RemoveAt 应该可以解决您的问题。您需要做的就是保存要删除的项目的引用,并将其作为参数传递给适当的删除方法除非您知道它在集合中的索引;在这种情况下,您可以使用它来删除它。
public void CreateALine(double x1, double y1)
{
// Create a Line
Line redLine = new Line();
redLine.X1 = x + 20;
redLine.Y1 = y + 20;
redLine.X2 = x1 + 20;
redLine.Y2 = y1 + 20;
SolidColorBrush gBrush = new SolidColorBrush();
gBrush.Color = Colors.Green;
redLine.StrokeThickness = 2;
redLine.Stroke = gBrush;
// Add line to the Canvas
canvas2.Children.Add(redLine);
}
这是我的代码,现在我想删除这一行,谁能告诉我该怎么做? 谢谢。
Children property is nothing more than a UIElementCollection object attached to the Canvas control.
UIElementCollection
对象有一些方法可以让您从自身删除对象,这可能因编程语言而异。
对于您的情况,Remove and RemoveAt 应该可以解决您的问题。您需要做的就是保存要删除的项目的引用,并将其作为参数传递给适当的删除方法除非您知道它在集合中的索引;在这种情况下,您可以使用它来删除它。