private void addMaterialButton_Click(object sender, RoutedEventArgs e) { CreateMaterialWindow createMaterialWindow1 = new CreateMaterialWindow(); createMaterialWindow1.ShowDialog(); if (createMaterialWindow1.MyDialogResult == true) { byte[] buffer = File.ReadAllBytes(createMaterialWindow1.pathTextBox.Text); Material m = new Material(); m.Name = createMaterialWindow1.titleTextBox.Text; m.Description = createMaterialWindow1.descriptionTextBox.Text; m.Data = buffer; m.MaterialType_Id = createMaterialWindow1.MaterialType_Id; m.MaterialTypes = model1.MaterialTypes.First(o => o.Id == m.MaterialType_Id); m.FileName = createMaterialWindow1.pathTextBox.Text.Substring(createMaterialWindow1.pathTextBox.Text.LastIndexOf('\\') + 1); foreach (Person x in createMaterialWindow1.PersonsToAdd) { m.Persons.Add(x); } Person p; p = model1.Persons.First(o => o.Id == Person_Id); materialsDataGrid.ItemsSource = p.Materials.Select(o => new { Id = o.Id, Название = o.Name, Описание = o.Description, Data = o.Data, }).ToList(); } }