index > Windows Presentation Foundation ("Avalon") > mouse events misfiring

mouse events misfiring

   

         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

pmarreddy

What event(s) are you listening for, and at what level? Depending on how you're listening for what, you will either get events per Shape or on the owning Canvas.

Note though that while we can likely help you learn about events on individual Shapes, Shape Elements cannot have children, so this specific scenario is not available to you.

-Adam Smith [MS]

Adam Smith MS
reply 2

You can use google to search for other answers

 

More Articles

• Repeating controls
• Custom Control - Generic.baml file not generated
• What's means NameScope
• XamlParseExeption using ZAM 3D object
• WPF in Vista OS applications?
• Pagination With Xaml(XBAP)
• Create Image from Background
• Questions about RenderTargetBitmap
• send mail code for yahoo account to rediff account in asp.net 2.0
• How to assign database/source of ListView programmatically in WPF...
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Editable TreeView
• FlowDocumentPageViewer find text
• How to access an object's animatable pro
• XBAP - WPF/E; data sources other than se
• Access a control in datatemplate of a Li
• Howto: make the Enter key work like the
• Auto for Height and Width in code
• Nested/Inner Classes and the x:Type Mark
• Resource Dictionary "Adding Stroke/
• WPF "Bugs" or "Features&q
• Skinning a ScrollViewer (How do I create
• Applying styles at runtime
• Refresh ImageBox
• How can I move and resize window without
• BindingContext in WPF

Hot Articles

• Change the color of page border in a Flo
• x:Static works as element but not as att
• How to Execute a XAML file in Work Flow(
• Cider and Events
• Scroll a ListView to bottom?
• App Positioning Per different types of R
• How does WPF Handle simple control focus?
• How to dispose BitmapSource?
• HwndHost and Menu Items
• How can I get perfect performance when I
• How do you walk the controls in a XAML p
• Resizable Panel
• Inherited Custom Image Control...
• WindowsFormsHost and AllowsTransparency=
• stupid question: how to use the "co

Recommend Articles

• What is 3-tier architecture?
• scrolling contents in a stackpanel which
• Strange flicker on window display ...
• Style a Canvas?
• Graph Drawing in xaml
• Is there a RadioButtonList equivalent fo
• RC1 of .NetFx 3.0 released on September
• Working with events that are coming from
• create and open a new window
• Browser Applications/ Navigation Applica
• Issue with WPF Designer in Vista Build 5
• Reading pixels of BitmapSource
• Read value of a Binding manually
• XBAP Session ID
• Project Crashs Upon Open,Close and Reope