change GraphicsOverlays Symbol color on click, ArcGIS runtime 100 .net

520
0
10-03-2017 07:43 PM
LY90
by
New Contributor II

I have a simple GraphicsOverlay symbol, how do I change the color of it on event triggered? My sample code shown below:

public MainPageViewModel() {         
// Create new Map without basemap         
Map = new Map(SpatialReference.Create(102100));         
 // Add the tile basemap only after the map has loaded so it doesn't block the map if offline         
Map.Loaded += (sender, e) => { Map.Basemap = Basemap.CreateImagery(); };          
// Setup the graphics layers         
GraphicsOverlay editGraphics = new GraphicsOverlay();         
editGraphics.Id = "MyGraphics";         
GraphicsOverlays.Add(editGraphics);          
// Add some test graphics          
SimpleMarkerSymbol pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, SystemColor.Red, 25);         
var point = new MapPoint(0, 0);         
Graphic mapPoint = new Graphic(point, pointSymbol);         
GraphicsOverlays["MyGraphics"].Graphics.Add(mapPoint);  
}     
public ICommand ColorButtonCommand { get; set; }     
public void ColorButtonTapped() {         
// Handle color code goes in here       
// pointSymbol.Color = SystemColor.Gray;      
}     
public bool CanColorButtonTapped()     
{         
return true;     
}


I thought of declaring my SimpleMarkerSymbol pointSymbol variable as a global variable, and simply change color like what I did in my commented out code pointSymbol.Color = SystemColor.Gray, But I think it is a bad approach, there should be a easy and clean way to handle it. Can Anyone help me on this? 

0 Replies