MainWindow.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Controls.Primitives;
  5. using System.Windows.Input;
  6. using System.Windows.Media;
  7. using System.Windows.Media.Animation;
  8. namespace MatrixXAMLOnly
  9. {
  10. /// <summary>
  11. /// Interaction logic for MainWindow.xaml
  12. /// </summary>
  13. public partial class MainWindow : Window
  14. {
  15. public MainWindow()
  16. {
  17. InitializeComponent();
  18. GridContentAddition.Visibility = Visibility.Visible;
  19. GridAdditionFrstTerm.Children.Add(CreateMatrix(5, 5));
  20. }
  21. private void BtnHamburgerMenu_Click(object sender, RoutedEventArgs e)
  22. {
  23. DoubleAnimation menuAnimation = new DoubleAnimation();
  24. menuAnimation.From = CurtainMenu.ActualWidth;
  25. menuAnimation.DecelerationRatio = 1.0;
  26. if (menuAnimation.From == 250)
  27. {
  28. menuAnimation.To = 0;
  29. menuAnimation.Duration = TimeSpan.FromSeconds(0.2);
  30. }
  31. else
  32. {
  33. menuAnimation.To = 250;
  34. menuAnimation.Duration = TimeSpan.FromSeconds(0.2);
  35. }
  36. CurtainMenu.BeginAnimation(WidthProperty, menuAnimation);
  37. }
  38. private Grid CreateMatrix(int a, int b)
  39. {
  40. Grid matrixGrid = new Grid();
  41. matrixGrid.Margin = new Thickness(25, 75, 25, 75);
  42. // Добавление колонок
  43. for (int i = 0; i < a; i++)
  44. {
  45. matrixGrid.ColumnDefinitions.Add(new ColumnDefinition());
  46. }
  47. // Добавление строк
  48. for (int j = 0; j < b; j++)
  49. {
  50. matrixGrid.RowDefinitions.Add(new RowDefinition());
  51. }
  52. // Добавление TextBox'ов
  53. for (int i = 0; i < a; i++)
  54. {
  55. for (int j = 0; j < b; j++)
  56. {
  57. TextBox textBox = new TextBox()
  58. {
  59. HorizontalContentAlignment = HorizontalAlignment.Center,
  60. VerticalContentAlignment = VerticalAlignment.Center
  61. };
  62. textBox.KeyDown += TextBox_KeyDown;
  63. Grid.SetColumn(textBox, i);
  64. Grid.SetRow(textBox, j);
  65. matrixGrid.Children.Add(textBox);
  66. }
  67. }
  68. return matrixGrid;
  69. }
  70. private void TextBox_KeyDown(object sender, KeyEventArgs e)
  71. {
  72. if (e.Key != Key.NumPad0 && e.Key != Key.D0 &&
  73. e.Key != Key.NumPad1 && e.Key != Key.D1 &&
  74. e.Key != Key.NumPad2 && e.Key != Key.D2 &&
  75. e.Key != Key.NumPad3 && e.Key != Key.D3 &&
  76. e.Key != Key.NumPad4 && e.Key != Key.D4 &&
  77. e.Key != Key.NumPad5 && e.Key != Key.D5 &&
  78. e.Key != Key.NumPad6 && e.Key != Key.D6 &&
  79. e.Key != Key.NumPad7 && e.Key != Key.D7 &&
  80. e.Key != Key.NumPad8 && e.Key != Key.D8 &&
  81. e.Key != Key.NumPad9 && e.Key != Key.D9)
  82. {
  83. e.Handled = true;
  84. }
  85. }
  86. }
  87. enum Operation
  88. {
  89. Addition,
  90. Difference,
  91. MultiplicationOnScalar,
  92. Transposition,
  93. MultiplicationOnTransposed,
  94. RowReplace,
  95. RowReplaceOnTranspositionVector,
  96. Inverse
  97. }
  98. }