ESRI.ArcGIS.Client.Toolkit.Legend.OnApplyTemplate C# (CSharp) Method

OnApplyTemplate() public method

When overridden in a derived class, is invoked whenever application code or internal processes (such as a rebuilding layout pass) call M:System.Windows.Controls.Control.ApplyTemplate.
public OnApplyTemplate ( ) : void
return void
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (!_isLoaded)
            {
                _isLoaded = true;

                if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this) && (Map == null || Map.Layers == null || Map.Layers.Count == 0))
                {
                    if (_legendTree.LayerItems == null)
                    {
                        // Create a basic hierachy for design :  Map Layer -> SubLayer -> LegendItemViewModel
                        LegendItemViewModel legendItem = new LegendItemViewModel()
                        {
                            Label = "LegendItem",
                            ImageSource = new BitmapImage(new Uri("/ESRI.ArcGIS.Client.Toolkit;component/Images/legendItem.png", UriKind.Relative)),
                        };

                        LayerItemViewModel layerItem = new LayerItemViewModel()
                        {
                            Label = "LayerItem",
                            LegendItems = new ObservableCollection<LegendItemViewModel>() { legendItem }
                        };

                        LayerItemViewModel mapLayerItem = new LayerItemViewModel()
                        {
                            Label = "MapLayerItem",
                            LayerType = MapLayerItem.c_mapLayerType,
                            LayerItems = new ObservableCollection<LayerItemViewModel>() { layerItem },
                        };

                        _legendTree.LayerItems = new ObservableCollection<LayerItemViewModel>() { mapLayerItem };
                    }

                }
                else
                {
                    // Initialize the Map now that all parameters are well known
                    _legendTree.Map = Map;
                }
            }
        }