Here is what the canvas looks like in Blend:
The following C# code does the heavy lifting to dynamically create an ‘offensive player’ (which is really an ellipse) and associated event handlers and is called by the ‘O’ button click event handler.
The following event handler removes the shapes that were dynamically created on the canvas. It assumes the existance of LayoutRoot and a global _shapeCount integer.
private void btnClearShapes_Click(object sender, System.Windows.RoutedEventArgs e){ // Make a copy of uielements in order to remove the desired shapes UIElement[] tmp = new UIElement[LayoutRoot.Children.Count]; LayoutRoot.Children.CopyTo(tmp, 0);
// Iterate the uielements foreach (UIElement uielement in tmp) { Shape myShape = uielement as Shape;
// Make sure we have a shape and the shape has a tag if (myShape != null && myShape.Tag != null) { // We only want to remove our dynamically created shapes if (myShape.Tag.ToString().Contains(“mycustomshape”)) { LayoutRoot.Children.Remove(uielement); } } }
_shapeCount = 0;}
No comments:
Post a Comment