private void RebuildTemplate(FeatureLayer flayer)
 {
     var templates = new List<TemplateItem>();
     FeatureServiceLayerInfo serviceInfo = null;
     var ft = flayer.FeatureTable;
     if (ft != null && !ft.IsReadOnly && flayer.Status == LayerStatus.Initialized)
     {
         try
         {
             serviceInfo = ft.ServiceInfo;
         }
         catch{}
     }
     if (serviceInfo != null)
     {
         var cmd = new InvokeCommand(OnItemClicked);
         var renderer = flayer.Renderer ?? (serviceInfo.DrawingInfo == null ? null : serviceInfo.DrawingInfo.Renderer);
         if (serviceInfo.Templates != null)
         {
             foreach (var template in serviceInfo.Templates)
             {
                 var item = new TemplateItem
                 {
                     Layer = flayer,
                     FeatureTemplate = template,
                     Command = cmd,
                 };
                 templates.Add(item);
                 if (renderer != null)
                 {
                     var g = new Graphic(template.Prototype.Attributes ?? Enumerable.Empty<System.Collections.Generic.KeyValuePair<string, object>>()); // Need to desambiguate from winstore toolkit KeyValuePair
                     item.SetSwatch(renderer.GetSymbol(g));
                 }
             }
         }
         if (serviceInfo.Types != null)
         {
             foreach (var type in serviceInfo.Types)
             {
                 foreach (var template in type.Templates)
                 {
                     var item = new TemplateItem
                     {
                         Layer = flayer,
                         FeatureType = type,
                         FeatureTemplate = template,
                         Command = cmd,
                     };
                     templates.Add(item);
                     if (renderer != null)
                     {
                         var g = new Graphic(template.Prototype.Attributes);
                         item.SetSwatch(renderer.GetSymbol(g));
                     }
                 }
             }
         }
     }
     _templatesByLayer[flayer] = templates;
 }
        private void RebuildTemplate(FeatureLayer flayer)
        {
            var templates = new List <TemplateItem>();
            FeatureServiceLayerInfo serviceInfo = null;
            var ft = flayer.FeatureTable;

            if (ft != null && !ft.IsReadOnly && flayer.Status == LayerStatus.Initialized)
            {
                try
                {
                    serviceInfo = ft.ServiceInfo;
                }
                catch {}
            }
            if (serviceInfo != null)
            {
                var cmd      = new InvokeCommand(OnItemClicked);
                var renderer = flayer.Renderer ?? (serviceInfo.DrawingInfo == null ? null : serviceInfo.DrawingInfo.Renderer);
                if (serviceInfo.Templates != null)
                {
                    foreach (var template in serviceInfo.Templates)
                    {
                        var item = new TemplateItem
                        {
                            Layer           = flayer,
                            FeatureTemplate = template,
                            Command         = cmd,
                        };
                        templates.Add(item);
                        if (renderer != null)
                        {
                            var g = new Graphic(template.Prototype.Attributes ?? Enumerable.Empty <System.Collections.Generic.KeyValuePair <string, object> >()); // Need to disambiguate from winstore toolkit KeyValuePair
                            item.SetSwatch(renderer.GetSymbol(g));
                        }
                    }
                }
                if (serviceInfo.Types != null)
                {
                    foreach (var type in serviceInfo.Types)
                    {
                        foreach (var template in type.Templates)
                        {
                            var item = new TemplateItem
                            {
                                Layer           = flayer,
                                FeatureType     = type,
                                FeatureTemplate = template,
                                Command         = cmd,
                            };
                            templates.Add(item);
                            if (renderer != null)
                            {
                                var g = new Graphic(template.Prototype.Attributes ?? Enumerable.Empty <System.Collections.Generic.KeyValuePair <string, object> >());
                                item.SetSwatch(renderer.GetSymbol(g));
                            }
                        }
                    }
                }
            }
            _templatesByLayer[flayer] = templates;
        }