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...
https://community.esri.com/t5/arcgis-pro-sdk-questions/trying-to-change-the-fill-color-of-a/m-p/1514160#M11930
CIMSymbol SetColor : https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic16566.html
CIMPolygonSymbol SetOutlineColor : https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic16567.html
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 graphicvar symbol = polygonGraphic.Symbol;
// Change the fill color of the symbol using SetColorif (symbol is CIMPolygonSymbol polygonSymbol){var solidFill = polygonSymbol.SymbolLayers.OfType<CIMSolidFill>().FirstOrDefault();if (solidFill != null){solidFill.SetColor(ColorFactory.Instance.RedRGB);}}
// Update the symbol in the graphicpolygonGraphic.Symbol = symbol;
Gives following errors:Severity Code Description Project File Line Suppression StateError 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 ActiveSeverity Code Description Project File Line Suppression StateError 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
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();
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.