How to set color property of symbols using Xamarin UWP project

1192
3
Jump to solution
03-15-2018 09:44 AM
TylerLawson
New Contributor III

Hello,

Currently, I am trying to get some symbols to display on a map using a xamarin uwp project, but I am having a problem reconciling the color properties of various symbols in UWP. It seems like the color properties (i.e TextColor, BackgroundColor, etc) are based on System.Drawing.Color, which is incompatible with UWP. Is there some way to set the color properties of the symbols in Esri.ArcGISRuntime.Symbology or are there any other options that would be more compatible with UWP that accomplish the same thing? I have tried using Xamarin.Color but so far it has not worked.

Example (Drawing a rectangle to put on map):

//Set draw mode and create geometry

Esri.ArcGISRuntime.UI.SketchCreationMode drawMode = Esri.ArcGISRuntime.UI.SketchCreationMode.Rectangle;
Esri.ArcGISRuntime.Geometry.Geometry geometry = await this.map.SketchEditor.StartAsync(drawMode, false);

//Create fill symbol

var fillSymbol = new Esri.ArcGISRuntime.Symbology.SimpleFillSymbol(SimpleFillSymbolStyle.Solid, color, new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, color, 2));

//color throws an error because it is not of the correct type

//Create graphic based on drawn geometry and fill symbol and add to map

var graphic = new Esri.ArcGISRuntime.UI.Graphic(geometry, fillSymbol);

this.map.GraphicsOverlays["MapShapes"].Graphics.Add(graphic);

Affected symbols and properties:

  • TextSymbol: BackgroundColor, Color, HaloColor, OutlineColor
  • SimpleFillSymbol: Color
  • SimpleLineSymbol: Color

NOTE: Symbols can be added to the map and manipulated by using the default symbol (default constructor with no arguments), however I have not been able to manipulate any symbol's color properties.

Any help on this issue would be appreciated.

0 Kudos
1 Solution

Accepted Solutions
JenniferNery
Esri Regular Contributor

You can add this conditional compile directive

#if NETFX_CORE
using Color = Windows.UI.Colors;
#else
using Color = System.Drawing.Color;
#endif

which should allow you to create symbols the same way as before. It may had just been trying to resolve Color using Xamarin.Forms so you need to select the appropriate namespace.

var symbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Cross, Color.Blue, null);

View solution in original post

3 Replies
JenniferNery
Esri Regular Contributor

You can add this conditional compile directive

#if NETFX_CORE
using Color = Windows.UI.Colors;
#else
using Color = System.Drawing.Color;
#endif

which should allow you to create symbols the same way as before. It may had just been trying to resolve Color using Xamarin.Forms so you need to select the appropriate namespace.

var symbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Cross, Color.Blue, null);
TylerLawson
New Contributor III

This seems to work perfectly. Thank you for the quick response.

0 Kudos
dotMorten_esri
Esri Notable Contributor

Note that with the upcoming Update 3 which adds support for .NET Standard, we'll be moving to System.Drawing.Color across all the platforms, so this won't be an issue by then. This is generally the only type you'll hit that differs from platform to platform, because there weren't a common color type until .NET Standard 2.0

0 Kudos