|
hi,
i am building window which will have a tree structure in it. the root node is a canvas and the child nodes are shapes.
my aim is to add new shapes nodes to the root or as sub child to another shape node (when i click on the shape node). but when i click on a child the node is getting created, but it is getting added to the root i.e (to canvas) instead to the shape node on which i am clicking.
how can i add a sub child to the shape nodes at run time? any kind of help will be of greate help to me.
my actual problem is with the sender some how when i clicking the intended node is not being clicked when more than one shape is occupying the space cordinates.
what kind of conceptual solutions exists (can we use adoners to put layers and select the intended layer if so are there any examples of hwo to do)
public void createShapeOnCanvas(object sender, MouseWheelEventArgs args) { Canvas _can = (Canvas)sender; _rectangle1 = new cubeRectangle(); p = System.Windows.Input.Mouse.GetPosition(_can); _rectangle1.Height = 30; _rectangle1.Width = 30; rand1 = rnd.Next(200); Canvas.SetLeft(_rectangle1, p.X += 1); Canvas.SetTop(_rectangle1, p.Y += 1); _rectangle1.SetName = rand1.ToString(); _can.Children.Add(_rectangle1); _rectangle1.PreviewMouseRightButtonDown += new MouseButtonEventHandler(createShape); }
public void createShape(object sender, MouseButtonEventArgs e) {
cubeRectangle rect1 = (cubeRectangle)sender; _rectangle1 = new cubeRectangle(); rand1 = rnd.Next(200); Canvas.SetLeft(rect1, rand1); Canvas.SetTop(rect1, rand1); rect1.Background = Brushes.DarkCyan; p = System.Windows.Input.Mouse.GetPosition(rect1); _rectangle1.Height = 30; _rectangle1.Width = 30; Canvas.SetLeft(_rectangle1, p.X+=1); Canvas.SetTop(_rectangle1, p.Y+=1); _rectangle1.SetName = rand1.ToString(); rect1.Children.Add(_rectangle1); _rectangle1.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(createShape1); }
thank you.
prasanth |