void expander_Collapsed(object sender, RoutedEventArgs e) { ToggleButton ex = sender as ToggleButton; expander = ex; if (ex != null) { MonitoredSystem ms = (MonitoredSystem)ex.Tag; MonitoredSystemState state = LayoutManager.Instance.GetMSState(ms.ID); var ms_id = ms.ID; var pluginName = (ex.FindName("PluginName") as TextBlock).Text; int level = state.Level; if (ms_id >= 0 && level >= 0) { if (state.ShownPlugins.Contains(pluginName)) { LayoutManager.Instance.SetMSState(ms_id, level, pluginName, false, true); } } } }