Change Cursor Over Graphic in EditVertices Mode

719
8
03-30-2011 02:34 PM
AndyWright
Occasional Contributor
I'm trying to detect when a graphic on a GraphicsLayer enters EditVertices mode so that I can change the mouse cursor when the user moves over it in that state.  I am not having much luck detecting when a given graphic enters into EditVertices mode.  I've tried to tie into the EditorActivated event, which only fires when an edit command is initiated.  I've tried the GraphicsLayer_PropertyChanged event, but that fires when a graphic is selected not when it is put into EditVertices mode.

Does anyone have any ideas on this one?
0 Kudos
8 Replies
JenniferNery
Esri Regular Contributor
You can use the Click event of the button that is associated to EditVertices and GraphicsLayer.MouseLeftButtonDown for this.

private void EditVertices_Click(object sender, System.Windows.RoutedEventArgs e)
{
 GraphicsLayer layer = this.MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
 layer.MouseLeftButtonDown += layer_MouseLeftButtonDown;
}

private void layer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
{
 GraphicsLayer layer = sender as GraphicsLayer;
 layer.MouseLeftButtonDown -= layer_MouseLeftButtonDown;
 //TODO: Change map cursor EditVertices is active.
}
0 Kudos
AndyWright
Occasional Contributor
Jennifer,

Thanks for your reply.  I'm actually trying to change the cursor only when the user mouses over the graphic that is in edit mode, then change it back to normal when they mouse out.  I haven't come up with a way to get the graphic that is currently in edit mode.  Once I do I can use the Graphic.MouseEnter and Graphic.MouseLeave events to change the cursor.  So my missing piece here is how do I detect which graphic on the graphics layer is currently being edited?  There doesn't seem to be an event on the Editor that fires when you select something in EditVertices mode.
0 Kudos
JenniferNery
Esri Regular Contributor
You can still do the code below, replace it with GraphicsLayer.MouseEnter event. e.Graphic should return you the graphic that is being edited. Use Editor.EditCompleted event(e.Action == Editor.EditAction.EditVertices) to change the cursor back.

Also, note that when EditVertices is active a new GraphicsLayer (with no ID) is added to your map layers. This holds a clone of the graphic being edited. So if you need to capture mouse events on this layer, you would need to grab the layer first from Map.Layers.CollectionChanged event.
0 Kudos
AndyWright
Occasional Contributor
Thanks for the reply Jennifer.  Your first suggestion causes the MouseEnter event to fire for all graphics in my graphics layer.  I just want it to fire for the graphic that is being edited.

Your second suggestion is an interesting piece of information, but I can't get any events to fire on that "editing" graphics layer.  I've tied into the Map.Layers.CollectionChanged event and I can get a handle on that editing graphics layer.  At that point I subscribe to a couple of its events, but no matter what I do those events do not get fired.  I can click on a graphic to start editing it, I can perform some edits, I can commit those edits, and no events on that editing graphics layer ever fire.

Do you actually have this working in your code somewhere?  In principal this is exactly what I'd like to be able to do, but it doesn't seem to be working.  Here's my code ...

void Layers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null && e.NewItems[0] is GraphicsLayer)
            {
                GraphicsLayer editLyr = e.NewItems[0] as GraphicsLayer;

                if (editLyr.ID == null)
                {
                    editLyr.MouseEnter += new GraphicsLayer.MouseEventHandler(editLyr_MouseEnter);
                    editLyr.MouseLeftButtonDown += new GraphicsLayer.MouseButtonEventHandler(editLyr_MouseLeftButtonDown);
                    editLyr.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(editLyr_PropertyChanged);
                }
            }
        }

        void editLyr_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            MessageBox.Show(e.PropertyName);
        }

        void editLyr_MouseEnter(object sender, GraphicMouseEventArgs e)
        {
            MessageBox.Show("MouseEnter");
        }

        void editLyr_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
        {
            MessageBox.Show("MouseLeftButtonDown");
        }
0 Kudos
JenniferNery
Esri Regular Contributor
Now that I think more about it, I realize that you cannot change the cursor over the graphic when it's in EditVertices mode. The symbol template we used for vertices change the cursor when they are selected and dragged. We are considering making EditVertices public like Draw so you can customize the symbols in the future. But the current version of the API does not have this capability.
0 Kudos
AndyWright
Occasional Contributor
Ok, thanks.  I'm going to go ahead and submit an enhancement request on the Silverlight Beta site.  I think it would be very useful if some kind of event was fired when a graphic entered into edit mode, so us developers could do something with it if we needed to.
0 Kudos
FrancoisChartrand
New Contributor III
We are considering making EditVertices public like Draw so you can customize the symbols in the future.


I think it would be very useful if some kind of event was fired when a graphic entered into edit mode, so us developers could do something with it if we needed to.


I totally agree with both features above. This would be a big improvement that would give a lot more flexibility to developers.
0 Kudos
JenniferNery
Esri Regular Contributor
Thanks for your feedback. Exposing EditGeometry also includes access to GeometryEdit event that tells you when EditStarted.
0 Kudos