Change graphic selection template

3641
5
Jump to solution
10-13-2014 03:34 AM
Labels (1)
NicolasVIOT
New Contributor II

Hi everyone,

I'm trying to change the selection template of a layer without success...

What I've donne :

  • In view :

<esri:GraphicsLayer ID="LinesLayer" MouseLeftButtonDown="LinesLayer_MouseLeftButtonDown" x:Name="_grl_line" SelectionColor="Transparent">

  • In graphic creation code  :

graphicLine.PropertyChanged += new PropertyChangedEventHandler((o, p) =>

{

    if (p.PropertyName != "Selected") return;

    var selectedLine = (Graphic)o;

    selectedLine.Symbol = selectedLine.Selected ? SelectedLineSymbol : DefaultLineSymbol;

});

And this is the result :

Sans titre.png

There still is a border on my lines objects and I want to hide it...

Thanks in advance.

0 Kudos
1 Solution

Accepted Solutions
JenniferNery
Esri Regular Contributor

If you left UseAcceleratedLayers=False (default), you can refer to the following SDK sample to see how you can update symbol template and update selection state via VisualStateManager. ArcGIS API for Silverlight - Interactive Samples | ArcGIS for Developers.

View solution in original post

0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor

If you left UseAcceleratedLayers=False (default), you can refer to the following SDK sample to see how you can update symbol template and update selection state via VisualStateManager. ArcGIS API for Silverlight - Interactive Samples | ArcGIS for Developers.

0 Kudos
NicolasVIOT
New Contributor II

Thanks for your help Jennifer !

What I've done :

  • In Application.xaml :

            <esri:LineSymbol x:Key="LineSymbol">

                <esri:LineSymbol.ControlTemplate>

                    <ControlTemplate>

                        <Path x:Name="Element"

  Stroke="Yellow"

  StrokeStartLineCap="Round"

  StrokeThickness="2"

  StrokeLineJoin="Round"

  StrokeEndLineCap="Round">

                            <VisualStateManager.VisualStateGroups>

                                <!--<VisualStateGroup x:Name="CommonStates">

                                        <VisualState x:Name="MouseOver">

                                            <Storyboard>

                                                <ColorAnimation Storyboard.TargetName="Element"

                                                Storyboard.TargetProperty="(Path.Stroke).(SolidColorBrush.Color)"

                                                To="Orange" />

                                            </Storyboard>

                                        </VisualState>

                                    </VisualStateGroup>-->

                                <VisualStateGroup x:Name="SelectionStates">

                                    <VisualState x:Name="Unselected" />

                                    <VisualState x:Name="Selected">

                                        <Storyboard>

                                            <ColorAnimation Storyboard.TargetName="Element"

  Storyboard.TargetProperty="(Path.Stroke).(SolidColorBrush.Color)"

  To="Orange" Duration="00:00:00.25" />

                                            <DoubleAnimation Storyboard.TargetName="Element"

  Storyboard.TargetProperty="StrokeThickness"

  To="3"  Duration="00:00:00.25" />

                                        </Storyboard>

                                    </VisualState>

                                </VisualStateGroup>

                            </VisualStateManager.VisualStateGroups>

                        </Path>

                    </ControlTemplate>

                </esri:LineSymbol.ControlTemplate>

            </esri:LineSymbol>

            <esri:LineSymbol x:Key="LineOverSymbol">

                <esri:LineSymbol.ControlTemplate>

                    <ControlTemplate>

                        <Path x:Name="Element"

  Stroke="LimeGreen"

  StrokeStartLineCap="Round"

  StrokeThickness="2"

  StrokeLineJoin="Round"

  StrokeEndLineCap="Round">

                            <VisualStateManager.VisualStateGroups>

                                <!--<VisualStateGroup x:Name="CommonStates">

                                        <VisualState x:Name="MouseOver">

                                            <Storyboard>

                                                <ColorAnimation Storyboard.TargetName="Element"

                                                Storyboard.TargetProperty="(Path.Stroke).(SolidColorBrush.Color)"

                                                To="Orange" />

                                            </Storyboard>

                                        </VisualState>

                                    </VisualStateGroup>-->

                                <VisualStateGroup x:Name="SelectionStates">

                                    <VisualState x:Name="Unselected" />

                                    <VisualState x:Name="Selected">

                                        <Storyboard>

                                            <ColorAnimation Storyboard.TargetName="Element"

  Storyboard.TargetProperty="(Path.Stroke).(SolidColorBrush.Color)"

  To="Green" Duration="00:00:00.25" />

                                            <DoubleAnimation Storyboard.TargetName="Element"

  Storyboard.TargetProperty="StrokeThickness"

  To="3"  Duration="00:00:00.25" />

                                        </Storyboard>

                                    </VisualState>

                                </VisualStateGroup>

                            </VisualStateManager.VisualStateGroups>

                        </Path>

                    </ControlTemplate>

                </esri:LineSymbol.ControlTemplate>

            </esri:LineSymbol>

  • In my Graphics factory :

        ...

        public static LineSymbol LineSymbol = App.Current.Resources["LineSymbol"] as LineSymbol;

        public static LineSymbol LineOverSymbol = App.Current.Resources["LineOverSymbol"] as LineSymbol;

         ...

            graphicLine.MouseEnter += new MouseEventHandler((o, m) =>

            {

                var lineGraphic = (Graphic)o;

                lineGraphic.Symbol = LineOverSymbol;

            });

            graphicLine.MouseLeave += new MouseEventHandler((o, m) =>

            {

                var lineGraphic = (Graphic)o;

                lineGraphic.Symbol = LineSymbol;

            });

And I get this error when I try to add graphics to my layer :

linesLayer.Graphics.Add(graphicLine);

Error : Graphic Symbol n’est pas sérialisable sur JSON

Sans titre.png

Have you an idea on what is the problem ?

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

The error "Graphic Symbol is not serializable to JSON" is caused by using custom symbols (i.e. ControlTemplates) with the accelerated display mode. As Jennifer noted, in order to use such custom symbols you will need to set Map.UseAcceleratedDisplay to False.

Ideally we recommend you should use the accelerated display mode which is particularly beneficial for GraphicsLayers and FeatureLayers in WPF. Additionally, this will help your migration to the new .NET SDK in which the accelerated display mode is the only map rendering mode.

One way around this is to consider using a UniqueValueRenderer with two classes/values and two different symbols instead of selections and use an attribute change to indicate selected state of your graphics.

Cheers

Mike

0 Kudos
NicolasVIOT
New Contributor II

Oh sorry.. my fault I didn't saw I had set UseAcceleratedDisplay to True...

Thanks you two very much.

Michael Branscomb a écrit:

Ideally we recommend you should use the accelerated display mode which is particularly beneficial for GraphicsLayers and FeatureLayers in WPF. Additionally, this will help your migration to the new .NET SDK in which the accelerated display mode is the only map rendering mode.

Is the accelerated display mode optimized the display of my objects on map and by the way upgrade the fluidity of my application?

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

Correct, the accelerated display is an optimized map rendering engine. You may not notice any significant difference for tiled and dynamic map service layers but you should notice a substantial difference when using GraphicsLayers and FeatureLayers. But there are some drawbacks - custom symbols and KML layers are not supported in this mode.

There are some additional guidelines to using the accelerated display mode in the .NET Guide documentation: Performance considerations—ArcGIS Runtime SDK for .NET | ArcGIS for Developers (it will not mention the "accelerated display" because it only uses that display pipeline).

Of particular note is the advice on Dynamic and Static rendering modes, which are supported in the WPF API on GraphicsLayers and FeatureLayers (ArcGIS Runtime SDK for Microsoft WPF - Library Reference ).

Cheers

Mike

0 Kudos