using GsConfigTool.Models; using GsConfigTool.ViewModels; using System.Collections.Specialized; using System.Windows; using System.Windows.Controls; namespace GsConfigTool.Views; public partial class ProjectsPage : UserControl { public ProjectsPage() { InitializeComponent(); DataContextChanged += OnDataContextChanged; } private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (e.NewValue is ProjectsViewModel vm) { vm.Projects.CollectionChanged += (_, _) => UpdateEmptyState(vm); vm.PropertyChanged += (_, args) => { if (args.PropertyName == nameof(ProjectsViewModel.Projects)) UpdateEmptyState(vm); }; UpdateEmptyState(vm); } } private void UpdateEmptyState(ProjectsViewModel vm) { if (EmptyState != null) EmptyState.Visibility = vm.Projects.Count == 0 ? Visibility.Visible : Visibility.Collapsed; } private void OpenProject_Click(object sender, RoutedEventArgs e) { if (sender is Button btn && btn.Tag is ServerProject project) { var main = Application.Current.MainWindow?.DataContext as MainViewModel; main?.OpenProject(project); } } }