Select to view content in your preferred language

multiple times MouseLeftButtonDown on GraphicsLayer problem

645
2
12-12-2011 12:13 PM
DeminHu
Deactivated User
Hi,

I  experienced a problem  with multiple times MouseLeftButtonDown on the same graphicsLayer, now I figured out how to avoid this problem, but I hope I could get better idea how to handle the issue.

My problem is like the following:

#1. I have an application with two  user controls called userControl1, usercontrol2, a graphicsLayer called gLayer

#2. In the MainPage,  int the  UserControl_Loaded function like this :
     control1 = new userControl1( map, gLayer);
     control2  = new  usercontrol2(map, gLayer);

  in the userControl1 code, have some processes like :  gLayer.graphics.Clear() -> gLayer.Graphics.Add(graphic) ->   gLayer.MouseLeftButtonDown +=new GraphicsLayer.MouseButtonEventHandler ( gLayer_MouseLeftButtonDown1), then do something

  in the usercontrol2 code have processes like : gLayer.graphics.Clear() -> gLayer.Graphics.Add(graphic) -> gLayer.MouseLeftButtonDown +=new GraphicsLayer.MouseButtonEventHandler ( gLayer_MouseLeftButtonDown2), then do something else.

#3. When I stated the application, with user controls1, it would be OK, but with usercontrol2, when  mouseLeftButtondown on gLayer,  I got the error : Required parameter is null or empty. Parameter name : graphics

#4. If in the UserControl_Loaded function  of the MainPage, put control2 over control1, then the error would come with control1, control2 would be OK.

#5, When I used 2 graphicslayers for control1 and control2 respectively, it would be OK.  Since in my application, I have many controls need to call the same graphicslayer and click on the same  layer, I hope I could find a better way.

Thanks in advance for your help.
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
Could you share a simple test page allowing to reproduce the issue?
0 Kudos
DeminHu
Deactivated User
Hi, Dominique

Thank you so much , I tested again, I realized I made a very silly mistaken for a complicated situation.  My mistake like the following  :

#1.  in Main Page,  UserCotrol_load funtion, I have something like this :
            Control1 ctrl1 = new Control1(TestMap, testGLayer);
            Control1Panel.Children.Add(ctrl1);
             Control2 ctrl2 = new Control2(TestMap, testGLayer);
            Control2Panel.Children.Add(ctrl2);
       in Control1 code :  testGLayer.MouseLeftButtonDown -> dosomething()
       in Control2 code : testGLayer.MouseLeftButtonDown -> dosomethingelse()

#2. When we start the application,  whenever, click the GLayer, it will excute both  :dosomething(),dosomethingelse(),  not one of them.

Thanks again for your time.
0 Kudos