MainWindow.axaml.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Avalonia.Controls;
  2. using EntranseTesting.Models;
  3. using EntranseTesting.ViewModels;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. namespace EntranseTesting.Views
  8. {
  9. public partial class MainWindow : Window
  10. {
  11. public MainWindow()
  12. {
  13. InitializeComponent();
  14. TestContent.SizeChanged += Resize;
  15. MyFontSize.ValueChanged += ChangeSize;
  16. }
  17. private void ChangeSize(object? sender, NumericUpDownValueChangedEventArgs e)
  18. {
  19. if (((NumericUpDown)sender).Value > 8 && ((NumericUpDown)sender).Value < 30)
  20. Resize();
  21. }
  22. private void Resize(object? sender, SizeChangedEventArgs e)
  23. {
  24. if (DataContext is not MainWindowViewModel vm) return;
  25. Resize();
  26. }
  27. public void Resize()
  28. {
  29. //ãëàâíàÿ vm
  30. if (DataContext is not MainWindowViewModel vm) return;
  31. //äîñòóïíîå ïîëå
  32. double widht = TestContent.Bounds.Width - 15.0 * 2;
  33. //äëèíà êíîïêè
  34. double widhtButton = 50.0 * (double)MyFontSize.Value / 14.0;
  35. double widhrButtonNav = 23.0 * (double)MyFontSize.Value / 14.0;
  36. widhrButtonNav = (widhrButtonNav < 25) ? 25 : widhrButtonNav;
  37. widht -= widhrButtonNav * 2;//àêòóàëüíàÿ äëèíà äëÿ ïîëÿ
  38. //ñêîëüêî ýëåìåíòîâ ïîìåñòèòüñÿ
  39. int count = (int)Math.Round(widht / (widhtButton + 5.0));
  40. if (count * (widhtButton + 5.0) > widht)
  41. count--;
  42. vm.TestMain.TestPages.TakeItem = count;
  43. //íàñòðîéêà ëèíåéêè
  44. List<ItemProgressButton> items = vm.TestMain.TestPages.ProgressButtons;
  45. int num = vm.TestMain.TestPages.NumQuestion;
  46. ItemProgressButton item = vm.TestMain.TestPages.ProgressButtons[num - 1];
  47. if (vm.UC.GetType() == typeof(TestPage))
  48. {
  49. while (!vm.TestMain.TestPages.TakeProgressButtons.Contains(item))
  50. {
  51. if (num > vm.TestMain.TestPages.TakeProgressButtons.Last().Num)
  52. vm.TestMain.TestPages.SkipItem++;
  53. else
  54. vm.TestMain.TestPages.SkipItem--;
  55. }
  56. while (vm.TestMain.TestPages.TakeProgressButtons.Count < count)
  57. {
  58. if (vm.TestMain.TestPages.SkipItem > 0) vm.TestMain.TestPages.SkipItem--;
  59. else break;
  60. }
  61. }
  62. InterfaceSettings.take = count;
  63. }
  64. }
  65. }