Highlight graphics from results window mouse over

2531
4
10-15-2010 10:38 AM
ChrisBradberry
Occasional Contributor
Hey,

I have the results from a querytask in a drop down window.  The locations are displayed with a graphic.  I was wondering how to highlight or change the graphic when you mouse over the results in the dropdown window. I would like the user to know which graphic goes with the result.

Thanks, Chris
0 Kudos
4 Replies
dotMorten_esri
Esri Notable Contributor
I usually define a selection state on the graphic, and when I perform a roll-over, set the graphic to selected, and unselected when I roll out again.
Here's an example of this in action:
http://resources.esri.com/arcgisserver/apis/silverlight/index.cfm?fa=codeGalleryDetails&scriptID=161...
(note that this is a very old sample and was written with v1.0beta, so a couple things might have changed, but the idea is the same)
0 Kudos
ChrisBradberry
Occasional Contributor
Thanks Morten,
That is exactly what I want.

Chris
0 Kudos
ChrisBradberry
Occasional Contributor
Here is the code that I used to get it to work.

Chris
 private void TextBlock_MouseEnter(object sender, MouseEventArgs e)
        {
            
            QueryResultData HiLight = (QueryResultData)(sender as FrameworkElement).DataContext;
            
            Graphic g = getGraphic(HiLight);

            g.Symbol = SearchSelectedSymbol;
            if (g != null)
            {
                g.Select();
                g.SetZIndex(1);
            }
        }

        private void TextBlock_MouseLeave(object sender, MouseEventArgs e)
        {
            QueryResultData HiLight = (QueryResultData)(sender as FrameworkElement).DataContext;

            Graphic g = getGraphic(HiLight);

            g.Symbol = SearchPictureSymbol;
            if (g != null)
            {
                g.Select();
                g.SetZIndex(0);
            }
        }

       
        private Graphic getGraphic(QueryResultData HiLight)
        {
            GraphicsLayer layer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
            if (HiLight != null && layer != null)
            {
             
                foreach (Graphic g in layer.Graphics)
                {
                    
                    if (g.Geometry == HiLight.SHAPE)
                    {
                        return g;
                    }
                }
            }
            return null;
        }
        
0 Kudos
dotMorten_esri
Esri Notable Contributor
A much more efficient way would be to use the visual states instead of replacing the symbol as suggested. It will perform better and not "flicker".
0 Kudos