Select to view content in your preferred language

Trying to change the fill color of a graphicelement...

54
1
yesterday
Gurunara
Occasional Contributor

using following to change the fill color of graphicelement:

QueuedTask.Run(() =>
{
// Access the CIM definition of the graphic element
var cimElement = graphicElement.GetDefinition() as CIMElement;
if (cimElement == null)
return;

// Get the current background symbol
var currentSymbol = graphicElement.GetGraphic().Symbol;

// Check if the symbol is a fill symbol
if (currentSymbol is CIMSymbolReference polygonSymbol)
{
// Change the fill color
polygonSymbol.Symbol = SymbolFactory.Instance
.ConstructPolygonSymbol(ColorFactory.Instance.CreateColor(newColor));

// Apply the modified symbol back to the GraphicElement
graphicElement.GetGraphic().Symbol = polygonSymbol;
}

// Apply the changes back to the graphic element
graphicElement.SetDefinition(cimElement);
});

 

No compile/runtime error, but the color does not change on UI...
Any inputs..?

Is there another way to change the color or flash/highlight a given graphicelement on a graphicslayer?

0 Kudos
1 Reply
CharlesMacleod
Esri Regular Contributor

You are close, - almost there. Use graphicElement.SetGraphic(...) - https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic11077.html - to apply the changes to the graphic symbol _back_ to the element. There is a code snippet there u can use.

 

 

 

 

0 Kudos