# Создание окна ## MainWindow.xaml.cs ``` using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Input; using System.Windows.Media; namespace WpfApp3 { public partial class MainWindow : Window { public ObservableCollection StudentList { get; set; } private Dictionary filters = new Dictionary(); private string currentStyle = "StackStyle"; public MainWindow() { InitializeComponent(); DataContext = this; Globals.dataProvider = new LocalDataProvider(); StudentList = new ObservableCollection(Globals.dataProvider.GetStudents()); List styles = new List { "light", "dark" }; styleBox.SelectionChanged += ThemeChange; styleBox.ItemsSource = styles; styleBox.SelectedItem = "dark"; Style buttonStyle = new Style(); buttonStyle.Setters.Add( new Setter { Property = Control.FontFamilyProperty, Value = new FontFamily("Verdana") }); buttonStyle.Setters.Add( new Setter { Property = Control.MarginProperty, Value = new Thickness(10) }); buttonStyle.Setters.Add( new Setter { Property = Control.BackgroundProperty, Value = new SolidColorBrush(Colors.PowderBlue) }); buttonStyle.Setters.Add( new Setter { Property = Control.ForegroundProperty, Value = new SolidColorBrush(Colors.Black) }); } private void ExitButton_Click(object sender, RoutedEventArgs e) { Application.Current.Shutdown(); } private void NameFilter_TextChanged(object sender, TextChangedEventArgs e) { filters["Name"] = ((TextBox)sender).Text; ApplyFilter(); } private void NationFilter_TextChanged(object sender, TextChangedEventArgs e) { filters["Nation"] = ((TextBox)sender).Text; ApplyFilter(); } private void ApplyFilter() { var filteredStudents = Globals.dataProvider.GetStudents(); foreach (var filter in filters) { filteredStudents = filteredStudents.Where(s => s.GetType().GetProperty(filter.Key).GetValue(s, null).ToString().Contains(filter.Value.ToString())); } filteredStudents = filteredStudents.Where(s => s.Age >= 20 && s.Course > 2); StudentList = new ObservableCollection(filteredStudents); } private void ThemeChange(object sender, SelectionChangedEventArgs e) { string style = styleBox.SelectedItem as string; var uri = new Uri(style + ".xaml", UriKind.Relative); ResourceDictionary resourceDict = Application.LoadComponent(uri) as ResourceDictionary; Application.Current.Resources.Clear(); Application.Current.Resources.MergedDictionaries.Add(resourceDict); } private void ToggleViewButton_Click(object sender, RoutedEventArgs e) { currentStyle = currentStyle == "StackStyle" ? "WrapStyle" : "StackStyle"; var newStyle = (Style)TryFindResource(currentStyle); if (newStyle != null) StudentListBox.Style = newStyle; } private void StudentListBox_MouseDoubleClick( object sender, MouseButtonEventArgs e) { // в создаваемое окно передаем выбранного котика var detailsWindow = new Windows.StudentDetailsWindow( StudentListBox.SelectedItem as Student); detailsWindow.ShowDialog(); } } internal interface IDataProvider { IEnumerable GetStudents(); } public class LocalDataProvider : IDataProvider { public IEnumerable GetStudents() { return new List { new Student { Id = 1, Name = "Хэй Вэнь", Age = 24, Country = "Китай", GPA = 5.0, Speciality = "Программирование", Grant = 25000.0, Course = 4, EnrollmentDate = new DateTime(2020, 9, 1), IsFullTime = true }, new Student { Id = 2, Name = "Семен Хомяк", Age = 22, Country = "Россия", GPA = 3.7, Speciality = "Инженерия", Grant = 10000.0, Course = 2, EnrollmentDate = new DateTime(2022, 1, 15), IsFullTime = false }, new Student { Id = 3, Name = "Джейкоб Ли", Age = 19, Country = "Америка", GPA = 4.4, Speciality = "Лингвистика", Grant = 20000.0, Course = 1, EnrollmentDate = new DateTime(2023, 8, 20), IsFullTime = true }, new Student { Id = 4, Name = "Арамсунторнсук Пирапонг", Age = 18, Country = "Таиланд", GPA = 4.1, Speciality = "Логистика", Grant = 15000.0, Course = 1, EnrollmentDate = new DateTime(2023, 4, 6), IsFullTime = false }, new Student { Id = 5, Name = "Рипка Дарина", Age = 18, Country = "Украина", GPA = 4.8, Speciality = "Дизайн", Grant = 23000.0, Course = 1, EnrollmentDate = new DateTime(2023, 5, 15), IsFullTime = true }, }; } } public class Student { public int Id { get; set; } public string Name { get; set; } public string Speciality { get; set; } public string Country { get; set; } public double GPA { get; set; } public double Grant { get; set; } public DateTime EnrollmentDate { get; set; } public bool IsFullTime { get; set; } public int Age { get; internal set; } public int Course { get; internal set; } } } ``` ## MainWindow.xaml ```