Select to view content in your preferred language

Labeling a graphic using the ArcGIS Runtime for WPF

8253
10
01-21-2014 11:10 AM
Labels (1)
JenniferLink
Occasional Contributor
Hello,
I'm looking for a way to label a graphic using the ArcGIS Runtime for WPF. Previously, I accomplished this by creating a graphic that referenced a MarkerSymbol created in XAML. A TextBlock was used within the MarkerSymbol ControlTemplate to bind to an attribute of the graphic. The latest ArcGIS Runtime does not appear to support this. Could someone point out the correct objects I should be using to accomplish this? I need to dynamically set the label text associated with the graphic.
Thanks!
Jen

XAML

<Grid x:Name="LayoutRoot" Margin="0,0,-430.4,0.4">
        <Grid.Resources>
            <esri:MarkerSymbol x:Key="labelSymbol_10_1">
                <esri:MarkerSymbol.ControlTemplate>
                    <ControlTemplate>
                        <Grid>
                            <StackPanel Orientation="Horizontal">
                            <Ellipse Width="12" Height="12" Fill="Red" HorizontalAlignment="Left" VerticalAlignment="Top" />
                            <TextBlock Text="{Binding Attributes[NAME]}" FontSize="12" FontStyle="Oblique" FontWeight="Bold"></TextBlock>
                            </StackPanel>
                        </Grid>                        
                    </ControlTemplate>
                </esri:MarkerSymbol.ControlTemplate>
            </esri:MarkerSymbol>
        </Grid.Resources>


C#
 
ESRI.ArcGIS.Client.GraphicsLayer graphicsLayer10_1 = new ESRI.ArcGIS.Client.GraphicsLayer();

                ESRI.ArcGIS.Client.Symbols.MarkerSymbol marker10_1 = new ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol()
                {Size = 10, Style = ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol.SimpleMarkerStyle.Circle, };

                ESRI.ArcGIS.Client.Graphic graphic10_1 = new ESRI.ArcGIS.Client.Graphic()
                {
                    Geometry = new ESRI.ArcGIS.Client.Geometry.MapPoint()
                    {
                        X = -10764928.3045,
                        Y = 4985563.0066,
                    },
                    Selected = false,
                    Symbol = LayoutRoot.Resources["labelSymbol_10_1"] as ESRI.ArcGIS.Client.Symbols.MarkerSymbol,
                };

                graphic10_1.Attributes.Add("NAME", "Here I Am");
                graphicsLayer10_1.Graphics.Add(graphic10_1);
                myMap10_1.Layers.Add(graphicsLayer10_1);
0 Kudos
10 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

In order to label the military symbols you should use the UniqueDesignation property of the message to add a text label to the symbol. For an example please see the Message Processing sample (http://resources.arcgis.com/en/help/runtime-wpf/samples/index.html#/Message_Processing/02q2000000980...) and the corresponding  source XML file: "C:\Program Files (x86)\ArcGIS SDKs\WPF10.2.3\sdk\samples\data\symbology\Mil2525CMessages.xml".

Depending on your project delivery timescales, I would also encourage you to take a look at the new beta .NET SDK which includes a WPF-based API for building Windows Desktop apps. The military symbology functionality is essentially the same although we have improved the Message class by making it strongly typed (https://developers.arcgis.com/net/desktop/api-reference/html/AllMembers_T_Esri_ArcGISRuntime_Advance...). The new .NET SDK also includes a CompositeSymbol type and a labelling API for Graphics, although at present it may not make sense to use this directly in conjunction with military messages. We plan to have the initial release of the new .NET SDK in Summer 2014.


Cheers

Mike
0 Kudos