private void AttachLayersHandler(LayerCollection layers) { if (layers != null) { layers.CollectionChanged += Layers_CollectionChanged; // if one layer is not initialized, subscribe to Layers_Initialize event in order to update attribution items // This update is only useful to avoid blank lines (for any reason, a TextBlock with a null string has a null height the first time and a non null height after setting again the text value to null) if (!layers.All(layer => layer.IsInitialized)) layers.LayersInitialized += Layers_LayersInitialized; foreach (Layer layer in layers) AttachLayerHandler(layer); } }