PickAnimalPage.xaml.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace TamagochiProject.Pages
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для PickAnimalPage.xaml
  20. /// </summary>
  21. public partial class PickAnimalPage : Page
  22. {
  23. Animal PickAnimal;
  24. int Index = 0;
  25. public PickAnimalPage()
  26. {
  27. InitializeComponent();
  28. cbTypeAnimal.ItemsSource=Globals.Connection.Type.ToList();
  29. cbTypeAnimal.DisplayMemberPath = "Type1";
  30. cbTypeAnimal.SelectionChanged += cbTypeAnimal_SelectionChanged;
  31. }
  32. private void btnBegin_Click(object sender, RoutedEventArgs e)
  33. {
  34. if(tbNameAnimal.Text!="" && cbTypeAnimal.SelectedIndex!=-1)
  35. {
  36. PickAnimal = Globals.Connection.Animal.FirstOrDefault(x => x.Id_type == Index);
  37. PickAnimal.Name = tbNameAnimal.Text;
  38. Globals.PickAnimal = PickAnimal;
  39. Globals.Frame.Navigate(new MainAnimalPage());
  40. }
  41. else
  42. {
  43. MessageBox.Show("Выберите тип питомца и назовите!", "Ошибка");
  44. }
  45. }
  46. private void cbTypeAnimal_SelectionChanged(object sender, SelectionChangedEventArgs e)
  47. {
  48. int selectedIndex = cbTypeAnimal.SelectedIndex;
  49. if (selectedIndex != -1)
  50. {
  51. Index = selectedIndex + 1;
  52. }
  53. }
  54. }
  55. }