private Dog dogToEdit; // selected dog from dog List public DogEdit(Dog dogToEdit, ObservableCollection <Dog> dogs) { InitializeComponent(); this.dogs = dogs; this.dogToEdit = dogToEdit; // set all properties to window TextBoxName.Text = dogToEdit.Name; TextBoxChipNumber.Text = dogToEdit.ChipNumber; DoubleUpDownHeight.Value = dogToEdit.Height; DoubleUpDownWeight.Value = dogToEdit.Weight; CheckBoxCastration.IsChecked = dogToEdit.HaveCastration; // Set all colors List <Models.DB.Color> allColors = viewModelColors.GetColors(); // get all available colors in table Color IList <Models.DB.Color> colorInEditDog = viewModel.GetColors(dogToEdit); // get used colors in this dog ListBoxColors.ItemsSource = allColors; ListBoxColors.DisplayMemberPath = "Name"; // Which color should be selected foreach (Models.DB.Color colorShouldBeSelected in colorInEditDog) { ListBoxColors.SelectedItems.Add(allColors.Where(x => x.Name == colorShouldBeSelected.Name).FirstOrDefault()); } // Set minimum and maxiumum Date born DateTime maxYear = DateTime.Today.AddYears(-1); DatePickerBornDate.Maximum = maxYear; DatePickerBornDate.Minimum = DateTime.Today.AddYears(-200); if (dogToEdit.Sex == "K") { RadioButtonFemale.IsChecked = true; } else { RadioButtonMale.IsChecked = true; } // set cats combobox ComboBoxCats.ItemsSource = viewModelAttitudes.GetCatsattitudes(); ComboBoxCats.SelectedItem = viewModelAttitudes.GetCatsattitudesById(dogToEdit.IdCatsAttitude); ComboBoxCats.DisplayMemberPath = "Name"; // set dogs combobox ComboBoxDogs.ItemsSource = viewModelAttitudes.GetDogsattitudes(); ComboBoxDogs.SelectedItem = viewModelAttitudes.GetDogsattitudesById(dogToEdit.IdDogsAttitude); ComboBoxDogs.DisplayMemberPath = "Name"; // set kidscombobox ComboBoxKids.ItemsSource = viewModelAttitudes.GetKidsattitudes(); ComboBoxKids.SelectedItem = viewModelAttitudes.GetKidsattitudesById(dogToEdit.IdKidsAttitude); ComboBoxKids.DisplayMemberPath = "Name"; DatePickerBornDate.Value = dogToEdit.BornDate; TextBoxDescription.Text = dogToEdit.Description; }
public DogAdd() { InitializeComponent(); // Binding ComboBoxes with Attutudes from ViewModel ComboBoxDogs.ItemsSource = viewModelAttitudes.GetDogsattitudes(); ComboBoxDogs.DisplayMemberPath = "Name"; ComboBoxCats.ItemsSource = viewModelAttitudes.GetCatsattitudes(); ComboBoxCats.DisplayMemberPath = "Name"; ComboBoxKids.ItemsSource = viewModelAttitudes.GetKidsattitudes(); ComboBoxKids.DisplayMemberPath = "Name"; // Set all available colors ListBoxColors.ItemsSource = viewModelColors.GetColors(); ListBoxColors.DisplayMemberPath = "Name"; // Set minimum and maxiumum Date born DateTime maxYear = DateTime.Today.AddYears(-1); DatePickerBornDate.Value = maxYear; DatePickerBornDate.Maximum = maxYear; DatePickerBornDate.Minimum = DateTime.Today.AddYears(-200); }