2016-02-24 39 views
1
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); 

    } 

這是我的代碼,現在我想刪除這一行,誰能告訴我該怎麼做? 謝謝。uwp如何刪除一行

回答

0

Children property只不過是附加到Canvas controlUIElementCollection對象。

UIElementCollection對象有一些方法允許您從自身中刪除對象,這可能會因編程語言而異。

enter image description here

在你的情況下,RemoveRemoveAt應該解決您的問題。您只需保留要刪除的項目的引用,並將其作爲參數傳遞給適當的刪除方法,除非知道其集合中的索引;在這種情況下,您可以使用它來刪除它。