Select to view content in your preferred language

How to change the fill color for a GraphicElement

100
3
Friday
Gurunara
Occasional Contributor

There is GetGraphic() method and GetGraphic().Symbol for the GraphicElement, but how to change the fill color?

This is a graphicelement drawn on a graphicslayer using the Graphics tab on the ArcPro UI...

0 Kudos
3 Replies
Gurunara
Occasional Contributor

https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic16566.html is invalid link...

 

Have following: but 

CIMPolygonGraphic polygonGraphic = aoi.GetGraphic() as CIMPolygonGraphic;

// Access the symbol of the polygon graphic
var symbol = polygonGraphic.Symbol;

// Change the fill color of the symbol using SetColor
if (symbol is CIMPolygonSymbol polygonSymbol)
{
var solidFill = polygonSymbol.SymbolLayers.OfType<CIMSolidFill>().FirstOrDefault();
if (solidFill != null)
{
solidFill.SetColor(ColorFactory.Instance.RedRGB);
}
}

// Update the symbol in the graphic
polygonGraphic.Symbol = symbol;

 

 

Gives following errors:

Severity Code Description Project File Line Suppression State
Error CS8121 An expression of type 'CIMSymbolReference' cannot be handled by a pattern of type 'CIMPolygonSymbol'. EGIS.Core.Pro.Common C:\Users\EMSMP\Desktop\desktemp\repos\egis-Core-Pro-Common\Common\Data\MapProjectService.cs 185 Active

Severity Code Description Project File Line Suppression State
Error CS1929 'CIMSolidFill' does not contain a definition for 'SetColor' and the best extension method overload 'SymbolExtensionMethods.SetColor(CIMSymbol, CIMColor)' requires a receiver of type 'ArcGIS.Core.CIM.CIMSymbol' EGIS.Core.Pro.Common C:\Users\EMSMP\Desktop\desktemp\repos\egis-Core-Pro-Common\Common\Data\MapProjectService.cs 190 Active

0 Kudos
CharlesMacleod
Esri Regular Contributor

Change the color on the symbol, not the fill. 

if (symbol is CIMPolygonSymbol polygonSymbol)
   polygonSymbol.SetColor(....)

 

To change the color on a fill, use its color property.

var solidFill = polygonSymbol.SymbolLayers.OfType<CIMSolidFill>().FirstOrDefault();
     solidFill?.Color = .... ;

 

"Symbol" take a symbol reference not a symbol. An unfortunate property naming.

//polygonGraphic.Symbol = symbol;
polygonGraphic.Symbol = symbol.MakeSymbolReference();
0 Kudos