public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            object             name       = null;
            LayerItemViewModel layerModel = value as LayerItemViewModel;

            if (layerModel != null)
            {
                if (layerModel.Layer != null && MapContentsControlHelper.IsTopMostLayerType(layerModel.LayerType))
                {
                    string layerName = layerModel.Layer.GetValue(MapApplication.LayerNameProperty) as string;
                    if (string.IsNullOrWhiteSpace(layerName))
                    {
                        layerName = layerModel.Label;
                        if (string.IsNullOrWhiteSpace(layerName))
                        {
                            layerName = layerModel.Layer.ID;
                        }
                    }
                    name = layerName;
                }
                else
                {
                    name = layerModel.Label;
                }
            }
            else
            {
                LegendItemViewModel legendModel = value as LegendItemViewModel;
                if (legendModel != null)
                {
                    name = legendModel.Label;
                }
            }

            return(name);
        }
        private void CorrectRendererNodes(LegendItemViewModel model)
        {
            LayerItemViewModel mod = model as LayerItemViewModel;

            if (mod != null)
            {
                if (MapContentsControlHelper.IsTopMostLayerType(mod.LayerType))
                {
                    GraphicsLayer lay = mod.Layer as GraphicsLayer;
                    if (lay == null)
                    {
                        return;
                    }

                    ClassBreaksRenderer classBreaksrenderer = lay.Renderer as ClassBreaksRenderer;
                    if (classBreaksrenderer != null)
                    {
                        if (mod.LegendItems != null && mod.LegendItems.Count > 0 &&
                            string.IsNullOrWhiteSpace(mod.LegendItems[0].Label))
                        {
                            mod.LegendItems[0].Label = Resources.Strings.DefaultLegentItemViewModelLabel;
                        }
                    }
                    else
                    {
                        UniqueValueRenderer uniqueRenderer = lay.Renderer as UniqueValueRenderer;
                        if (uniqueRenderer != null && string.IsNullOrWhiteSpace(uniqueRenderer.DefaultLabel))
                        {
                            uniqueRenderer.DefaultLabel = Resources.Strings.DefaultLegentItemViewModelLabel;
                        }
                    }

                    //TODO:
                    //TODO: This code adds a new node for the renderer attribute field, but currently there is no
                    //TODO: way for us to set a different template as LayerItemViewModel.Template is read-only.
                    //TODO
                    //string attribute = null;
                    //ClassBreaksRenderer classBreaksrenderer = lay.Renderer as ClassBreaksRenderer;
                    //if (classBreaksrenderer != null)
                    //{
                    //    attribute = classBreaksrenderer.Attribute;
                    //}
                    //else
                    //{
                    //    UniqueValueRenderer uniqueRenderer = lay.Renderer as UniqueValueRenderer;
                    //    if (uniqueRenderer != null)
                    //        attribute = uniqueRenderer.Attribute;
                    //}
                    //if (renModel.LegendItems != null && renModel.LegendItems.Count > 0)
                    //{
                    //    if (string.IsNullOrWhiteSpace(renModel.LegendItems[0].Label))
                    //        renModel.LegendItems[0].Label = Resources.Strings.DefaultLegentItemViewModelLabel;
                    //}
                    //if (string.IsNullOrWhiteSpace(attribute))
                    //    return;
                    //LayerItemViewModel renModel = new LayerItemViewModel(mod.Layer);
                    //renModel.Label = attribute;
                    //renModel.LayerItems = mod.LayerItems;
                    //renModel.LegendItems = mod.LegendItems;
                    //renModel.Tag = AssociatedObject.DataContext;
                    //renModel.LayerType = "Renderer Layer";

                    //mod.LayerItems = null;
                    //mod.LegendItems = null;

                    //mod.LayerItems = new System.Collections.ObjectModel.ObservableCollection<LayerItemViewModel>();
                    //mod.LayerItems.Add(renModel);
                }
            }
        }