Click or drag to resize

SymbolStyle Class

A symbol style object.
Inheritance Hierarchy

Namespace:  Esri.ArcGISRuntime.Symbology
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.11.0
public class SymbolStyle

The SymbolStyle type exposes the following members.

Public propertyCredential
Gets or sets the Credential used to access a remote style.
Public propertyPortal
Gets the Portal that hosts the web style identified with Portal. This will be null if the style was identified with a PortalItem or Uri or a local .stylx file on disk.
Public propertyPortalItem
Gets the PortalItem representing the web style.
Public propertyStyleLocation
Gets the file location of the .stylx file on disk. This will be empty if the style was hosted on a portal (also referred to as a web style).
Public propertyStyleName
Gets the name of the web style. This will be empty if the web style was identified with a Uri or a PortalItem or a local .stylx file on disk.
Public propertyUri
Gets the Uri of the web symbol style item. This will be null if the style was identified with a PortalItem, style name or a local .stylx file on disk.
Public methodCode exampleGetDefaultSearchParametersAsync
Returns a Style Symbol Search Parameters object providing the default search parameters from the database.
Public methodCode exampleGetSymbolAsync
Asynchronously returns a symbol based on the provided list of keys.
Public methodStatic memberCode exampleOpenAsync(String)
Opens a SymbolStyle in the specified path.
Public methodStatic memberOpenAsync(Uri)
Opens a new SymbolStyle from a web style item Uri.
Public methodStatic memberOpenAsync(PortalItem)
Opens a new SymbolStyle object from a portal item. The portal item must be a web style.
Public methodStatic memberOpenAsync(String, ArcGISPortal)
Opens a new SymbolStyle from a portal item. The portal item must contain a webstyle style.
Public methodStatic memberOpenAsync(Uri, Credential)
Opens a new SymbolStyle from a secured web style item Uri.
Public methodCode exampleSearchSymbolsAsync
Returns a collection of SymbolStyleSearchResult objects.

A SymbolStyle is created either from a style file on disk (an SQLite database with a .stylx extension, created with ArcGIS Pro) or from a style file hosted on ArcGIS Online or an ArcGIS Enterprise portal (also referred to as a web style).

When used by itself, the symbol style supports two key workflows. One is to return a symbol based on a provided set of key values. Since each symbol in the style has a key that uniquely identifies it, you can pass an array of keys into GetSymbolAsync(IEnumerableString) to return a new Symbol built from the individual symbols represented by those keys. You might use this symbol to create a new Graphic.

The other common workflow is to use a standalone symbol style to search for symbol primitives. Symbol primitives are the individual symbols that compose more complex symbols. This is achieved using SearchSymbolsAsync(SymbolStyleSearchParameters). You could created a symbol picker app, for example, that searches for all symbols in the style that have the tag "maritime" in it. The search results contain symbols that you could use directly. You could also extract their individual symbol components to create a new multilayer symbol.



Example Name: SymbolsFromMobileStyle

Combine multiple symbols from a mobile style file into a single symbol.

Code example screen shot.

// Copyright 2019 Esri.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

using ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using WinMedia = System.Windows.Media;

namespace ArcGISRuntime.WPF.Samples.SymbolsFromMobileStyle
        name: "Read symbols from mobile style",
        category: "Symbology",
        description: "Combine multiple symbols from a mobile style file into a single symbol.",
        instructions: "Select a symbol and a color from each of the category lists to create an emoji. A preview of the symbol is updated as selections are made. The size of the symbol can be set using the slider. Click the map to create a point graphic using the customized emoji symbol, and click \"Reset\" to clear all graphics from the display.",
        tags: new[] { "advanced symbology", "mobile style", "multilayer", "stylx" })]
    public partial class SymbolsFromMobileStyle
        // A variable for the symbol style object.
        private SymbolStyle _emojiStyle;

        // The unique identifier (key) for the background face symbol in the mobile style.
        private readonly string _baseSymbolKey = "Face1";

        public SymbolsFromMobileStyle()

            // Call a function that will create the map and fill UI controls with symbols in a mobile style.

        private async void Initialize()
            // Create a new topographic basemap and assign it to the map view.
            Map map = new Map(BasemapStyle.ArcGISTopographic);
            MyMapView.Map = map;

            // Create a graphics overlay for showing point graphics and add it to the map view.
            GraphicsOverlay overlay = new GraphicsOverlay();

            // Fill the symbol color combo box with some color choices.
            FaceColorComboBox.SelectedIndex = 0;

            // Get the full path to the downloaded mobile style file (.stylx).
            string mobileStyleFilePath = DataManager.GetDataFolder("1bd036f221f54a99abc9e46ff3511cbf", "emoji-mobile.stylx");

            // Call a function that will read the mobile style file and populate list boxes with symbol layers.
            await ReadMobileStyle(mobileStyleFilePath);

            // Handle the tapped event on the map view to draw point graphics with the chosen symbol.
            MyMapView.GeoViewTapped += GeoViewTapped;

        private async Task ReadMobileStyle(string stylePath)
                // Open the mobile style file at the provided path.
                _emojiStyle = await SymbolStyle.OpenAsync(stylePath);

                // Get the default style search parameters.
                SymbolStyleSearchParameters searchParams = await _emojiStyle.GetDefaultSearchParametersAsync();

                // Search the style with the default parameters to return all symbol results.
                IList<SymbolStyleSearchResult> styleResults = await _emojiStyle.SearchSymbolsAsync(searchParams);

                // Create an empty placeholder image to represent "no symbol" for each category.
                WinMedia.ImageSource emptyImage = WinMedia.Imaging.BitmapSource.Create
                    (2, 2, 96, 96,
                     new WinMedia.Imaging.BitmapPalette(new List<WinMedia.Color> { WinMedia.Colors.Transparent }),
                     new byte[4],

                // Create lists to contain the available symbol layers for each category of symbol and add an empty entry as default.
                List<SymbolLayerInfo> eyeSymbolInfos = new List<SymbolLayerInfo> { new SymbolLayerInfo("", emptyImage, "") };
                List<SymbolLayerInfo> mouthSymbolInfos = new List<SymbolLayerInfo> { new SymbolLayerInfo("", emptyImage, "") };
                List<SymbolLayerInfo> hatSymbolInfos = new List<SymbolLayerInfo>() { new SymbolLayerInfo("", emptyImage, "") };

                // Loop through the results and put symbols into the appropriate list according to category.
                foreach (SymbolStyleSearchResult result in styleResults)
                    // Get the symbol for this result.
                    MultilayerPointSymbol multiLayerSym = result.Symbol as MultilayerPointSymbol;

                    // Create a swatch image from the symbol.
                    RuntimeImage swatch = await multiLayerSym.CreateSwatchAsync();
                    WinMedia.ImageSource symbolImage = await swatch.ToImageSourceAsync();

                    // Create a symbol layer info object to represent the symbol in the list.
                    // The symbol key will be used to retrieve the symbol from the style.
                    SymbolLayerInfo symbolInfo = new SymbolLayerInfo(result.Name, symbolImage, result.Key);

                    // Add the symbol layer info to the correct list for its category.
                    switch (result.Category)
                        case "Eyes":
                        case "Mouth":
                        case "Hat":

                // Show the symbols in the category list boxes.
                EyeSymbolList.ItemsSource = eyeSymbolInfos;
                MouthSymbolList.ItemsSource = mouthSymbolInfos;
                HatSymbolList.ItemsSource = hatSymbolInfos;

                // Call a function to construct the current symbol (default yellow circle).
                Symbol faceSymbol = await GetCurrentSymbol();

                // Call a function to show a preview image of the symbol.
                await UpdateSymbolPreview(faceSymbol);
            catch(Exception ex)
                MessageBox.Show("Error reading symbols from style: " + ex.Message);

        // Handler for the tapped event on the map view.
        private async void GeoViewTapped(object sender, GeoViewInputEventArgs e)
            // Call a function to get the currently defined multilayer point symbol.
            MultilayerPointSymbol faceSymbol = await GetCurrentSymbol();

            // Create a graphic for the tapped location using the current symbol and add it to the map view.
            Graphic graphic = new Graphic(e.Location, faceSymbol);

        // An event handler for list box and combo box selection changes that will update the current symbol.
        private async void SymbolPropertyChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
            // Call a function that will construct the current symbol.
            Symbol faceSymbol = await GetCurrentSymbol();

            // Call a function to update the symbol preview.
            await UpdateSymbolPreview(faceSymbol);

        private async Task<MultilayerPointSymbol> GetCurrentSymbol()
            // If the style hasn't been opened, return.
            if (_emojiStyle == null) { return null; }

            MultilayerPointSymbol faceSymbol = null;
                // Get the key that identifies the selected eye symbol (or an empty string if none selected).
                SymbolLayerInfo eyeLayerInfo = (SymbolLayerInfo)EyeSymbolList.SelectedItem;
                string eyeLayerKey = eyeLayerInfo != null ? eyeLayerInfo.Key : string.Empty;

                // Get the key that identifies the selected mouth symbol (or an empty string if none selected).
                SymbolLayerInfo mouthLayerInfo = (SymbolLayerInfo)MouthSymbolList.SelectedItem;
                string mouthLayerKey = mouthLayerInfo != null ? mouthLayerInfo.Key : string.Empty;

                // Get the key that identifies the selected hat symbol (or an empty string if none selected).
                SymbolLayerInfo hatLayerInfo = (SymbolLayerInfo)HatSymbolList.SelectedItem;
                string hatLayerKey = hatLayerInfo != null ? hatLayerInfo.Key : string.Empty;

                // Create a list of the symbol keys that identify the selected symbol layers, including the base (circle) symbol.
                List<string> symbolKeys = new List<string>
                    _baseSymbolKey, eyeLayerKey, mouthLayerKey, hatLayerKey

                // Get a multilayer point symbol from the style that contains the selected symbol layers.
                faceSymbol = await _emojiStyle.GetSymbolAsync(symbolKeys) as MultilayerPointSymbol;

                // Loop through all symbol layers and lock the color.
                foreach (SymbolLayer lyr in faceSymbol.SymbolLayers)
                    // Changing the color of the symbol will not affect this layer.
                    lyr.IsColorLocked = true;

                // Unlock the color for the base (first) layer. Changing the symbol color will change this layer's color.
                faceSymbol.SymbolLayers.First().IsColorLocked = false;

                // Set the symbol color from the combo box.
                if (FaceColorComboBox.SelectedItem != null)
                    faceSymbol.Color = (Color)FaceColorComboBox.SelectedItem;

                // Set the symbol size from the slider.
                faceSymbol.Size = SizeSlider.Value;
            catch (Exception ex)
                MessageBox.Show("Unable to create symbol: " + ex.Message, "Exception");

            // Return the multilayer point symbol.
            return faceSymbol;

        private async Task UpdateSymbolPreview(Symbol symbolToShow)
            if (symbolToShow == null) { return; }

            // Create a swatch from the symbol with a white background.
            RuntimeImage swatch = await symbolToShow.CreateSwatchAsync(80, 80, 96, Color.White);

            // Convert the swatch to an image source and show it in the Image control.
            WinMedia.ImageSource symbolImage = await swatch.ToImageSourceAsync();
            SymbolPreviewImage.Source = symbolImage;

        // A handler for the click event on the clear graphics button.
        private void ClearGraphicsClick(object sender, RoutedEventArgs e)
            // Clear all graphics from the first (only) graphics overlay in the map view.

    // A class for storing information about a symbol layer.
    public class SymbolLayerInfo
        // An image source for a preview image of the symbol.
        public WinMedia.ImageSource ImageSrc { get; private set; }

        // The name of the symbol as it appears in the mobile style.
        public string Name { get; private set; }

        // A key that uniquely identifies the symbol in the style.
        public string Key { get; private set; }

        // Take all symbol info in the constructor.
        public SymbolLayerInfo(string name, WinMedia.ImageSource source, string key)
            Name = name;
            ImageSrc = source;
            Key = key;

    // A class that converts a System.Drawing.Color object to a solid brush for setting background color for UI controls. 
    public class ColorToSolidBrushConverter : IValueConverter
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            // Get the input value as a System.Drawing.Color.
            Color inColor = (Color)value;

            // Convert the input System.Drawing.Color to a System.Windows.Media.Color.
            WinMedia.Color outColor = WinMedia.Color.FromArgb(inColor.A, inColor.R, inColor.G, inColor.B);

            // Create a solid color brush using the color and return it.
            WinMedia.SolidColorBrush brush = new WinMedia.SolidColorBrush(outColor);
            return brush;

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            throw new NotImplementedException();
<UserControl x:Class="ArcGISRuntime.WPF.Samples.SymbolsFromMobileStyle.SymbolsFromMobileStyle"
        <local:ColorToSolidBrushConverter x:Key="ColorToBrushConverter"/>
        <esri:MapView x:Name="MyMapView"/>
        <Border Style="{StaticResource BorderStyle}" 
                Padding="0" Width="400" Height="290" 
            <Grid Grid.Column="0">
                    <RowDefinition Height="140"/>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="40"/>
                <ListBox x:Name="EyeSymbolList"
                         Grid.Row="0" Grid.Column="0"
                            <Image Source="{Binding ImageSrc}"
                                   HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <ListBox x:Name="MouthSymbolList"
                         Grid.Row="0" Grid.Column="1"
                            <Image Source="{Binding ImageSrc}"
                                   HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <ListBox x:Name="HatSymbolList"
                         Grid.Row="0" Grid.Column="2"
                            <Image Source="{Binding ImageSrc}"
                                   HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <Slider x:Name="SizeSlider"
                        SmallChange="1" LargeChange="5"
                        Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
                        Minimum="8" Maximum="60" Value="20"/>
                <Label x:Name="SizeLabel" 
                       Grid.Row="1" Grid.Column="2">
                            <Run Text="Size:"/>
                            <Run Text="{Binding ElementName=SizeSlider, Path=Value, StringFormat={}{0:#}}"/>
                <ComboBox x:Name="FaceColorComboBox"
                          Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
                          Width="150" Height="25"
                          HorizontalAlignment="Center" VerticalAlignment="Center"
                                <Border Background="{Binding Converter={StaticResource ColorToBrushConverter}}" Height="25" Width="150"/>

                <Image x:Name="SymbolPreviewImage"
                       Grid.Row="2" Grid.Column="2" Grid.RowSpan="2"
                       Width="80" Height="80"/>
                <Button x:Name="ClearGraphicsButton"
                       Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2"
                       Width="140" Height="20"
                        Content="Clear graphics"
See Also
Additional Examples
Hyperlink to ExampleDescription
SymbolsFromMobileStyleCombine multiple symbols from a mobile style file into a single symbol.