Select to view content in your preferred language

LegendItem Question

655
2
06-05-2012 05:00 AM
JaredWhite
Regular Contributor
Does anyone know how you would remove legenditems from the legend without removing layeritems of maplayeritems? I'm trying to make a TOC for layers and a separate Legend swatch for my app, I've succesfully made a listbox populated with legenditems only, but cant seem to find a way to keep the legenditems from keeping at the very least a blank placeholder.

  <toolkit:Legend x:Name="theLegend" Map="{Binding ElementName=TabletMap}" Grid.Row="1" LayerItemsMode="Tree" ShowOnlyVisibleLayers="False" LayerIDs="ESRI Map Services, PESData"  Refreshed="Legend_Refreshed" >
                                    <toolkit:Legend.MapLayerTemplate>
                                        <DataTemplate >
                                            <StackPanel >
                                                <TextBlock Text="{Binding Label}" VerticalAlignment="Center" HorizontalAlignment="Left" FontWeight="Bold" Foreground="#FF32475D" FontSize="12" />
                                                <Slider Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="180" HorizontalAlignment="Right" />
                                            </StackPanel>
                                        </DataTemplate>
                                    </toolkit:Legend.MapLayerTemplate>
                                    <toolkit:Legend.LayerTemplate>
                                        <DataTemplate >
                                            <StackPanel Orientation="Horizontal">
                                                <CheckBox Content="{Binding Label}" IsChecked="{Binding IsEnabled, Mode=TwoWay}"/>
                                            </StackPanel>
                                        </DataTemplate>
                                    </toolkit:Legend.LayerTemplate>
                                    <esri:Legend.LegendItemTemplate>
                                        <DataTemplate>
                                        <Rectangle Visibility="Collapsed" />
                                    </DataTemplate>
                                    </esri:Legend.LegendItemTemplate>
                                </toolkit:Legend>


        private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e)
        {
            LayerItemViewModel removeLayerItemVM = null;

            if (e.LayerItem.LayerItems != null)
            {
                foreach (LayerItemViewModel layerItemVM in e.LayerItem.LayerItems)
                {
                    if (layerItemVM.LayerItems != null)
                         foreach (LayerItemViewModel sublayerItemVM in layerItemVM.LayerItems)
                             sublayerItemVM.IsVIsible = false;
                }

                
                if (removeLayerItemVM != null)
                    e.LayerItem.LayerItems.Remove(removeLayerItemVM);

            }
            else
            {
                e.LayerItem.IsExpanded = false;
            }

        }


It throws the error "Error 1 'ESRI.ArcGIS.Client.Toolkit.Primitives.LayerItemViewModel' does not contain a definition for 'IsVIsible' and no extension method 'IsVIsible' accepting a first argument of type 'ESRI.ArcGIS.Client.Toolkit.Primitives.LayerItemViewModel' could be found (are you missing a using directive or an assembly reference?)
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
You can set to null the LegendItemTemplate : in XAML : LegendItemTemplate="{x:Null}"
or by code sample here
0 Kudos
JaredWhite
Regular Contributor
You can set to null the LegendItemTemplate : in XAML : LegendItemTemplate="{x:Null}"
or by code sample here


Worked like a charm
Thanks again Dominique
0 Kudos