public void SaveSettings(IAppConfiguration configs) { foreach (var item in this.Items) { if (this.ItemContainerGenerator.ContainerFromItem(item) is DependencyObject container) { var dataContext = container.GetValue(DataContextProperty); if (dataContext != null) { configs.SetValue(typeof(BrowserItemsControl), dataContext.GetType(), nameof(ModernExpander.IsExpanded), GetIsExpanded(container)); } } } }