С горем пополам написал функцию для передачи значений из выпадающего списка в матрицу (matrix_dimensions_changed), но на выходе ошибка с кодом CS1061 - «MainWindow» не содержит определения для «Matrix1_width_SelectionChanged» public partial class MainWindow : Window {
double[,] Matrix1;
double[,] Matrix2;
double[,] Result;
public MainWindow()
{
InitializeComponent();
}
// Taking values into grid3 block from result array
private void initializeGrid(Grid grid, double [,] matrix)
{
if (grid != null)
{
// Reset the grid before doing anything
grid.Children.Clear();
grid.ColumnDefinitions.Clear();
grid.RowDefinitions.Clear();
// Get the dimensions
int columns = matrix.GetLength(0);
int rows = matrix.GetLength(1);
// Add the correct number of coumns to the grid
for (int x = 0; x < columns; x++)
{
// GridUnitType.Star - The value is expressed as a weighted proportion of available space
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star), });
}
for (int y = 0; y < rows; y++)
{
// GridUnitType.Star - The value is expressed as a weighted proportion of available space
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star), });
}
// Fill each cell of the grid with an editable TextBox containing the value from the matrix
for (int x = 0; x < columns; x++)
{
for (int y = 0; y < rows; y++)
{
double cell = (double)matrix[x, y];
TextBox t = new TextBox();
t.Text = cell.ToString();
t.VerticalAlignment = System.Windows.VerticalAlignment.Center;
t.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
t.SetValue(Grid.RowProperty, y);
t.SetValue(Grid.ColumnProperty, x);
grid.Children.Add(t);
}
}
}
}
//Taking values into grid1 and grid2 from matrix1 and matrix2 arrays
private void getValuesFromGrid(Grid grid, double[,] matrix)
{
int columns = grid.ColumnDefinitions.Count;
int rows = grid.RowDefinitions.Count;
// Iterate over cells in Grid, copying to matrix array
for (int c = 0; c < grid.Children.Count; c++)
{
TextBox t = (TextBox)grid.Children[c];
int row = Grid.GetRow(t);
int column = Grid.GetColumn(t);
matrix[column, row] = double.Parse(t.Text);
}
}
private void matrix_dimensions_changed (object Sender, SelectionChangedEventArgs e)
{
int m1rows = 1;
int m2columns = 1;
int m1columns_m2rows = 1;
if (Matrix1_width != null) m1columns_m2rows = Matrix1_width.SelectedIndex + 1;
if (Matrix1_height != null) m1rows = Matrix1_height.SelectedIndex + 1;
if (Matrix2_width != null) m2columns = Matrix2_width.SelectedIndex + 1;
Matrix1 = new double[m1columns_m2rows, m1rows];
Matrix2 = new double[m2columns, m1columns_m2rows];
Result = new double[m2columns, m1rows];
Random rand = new Random();
for (int i=0; i<m1columns_m2rows; i++)
{
for (int j=0; j<m1rows; j++)
Matrix1[i, j] = rand.Next(1, 99);
for (int j = 0; j < m2columns; j++)
Matrix2[j, i] = rand.Next(1, 99);
}
initializeGrid(grid1, Matrix1);
initializeGrid(grid2, Matrix2);
initializeGrid(grid3, Result);
}
private void Calculate_Button_Click(object sender, RoutedEventArgs e)
{
if (Matrix1_width.SelectedIndex == -1)
{
MessageBox.Show("Выберите количество столбцов для первой матрицы!", "Ошибка");
return;
}
if (Matrix1_height.SelectedIndex == -1)
{
MessageBox.Show("Выберите количество строк для первой матрицы!", "Ошибка");
return;
}
if (Matrix2_width.SelectedIndex == -1)
{
MessageBox.Show("Выберите количество столбцов для второй матрицы", "Ошибка");
return;
}
getValuesFromGrid (grid1, Matrix1);
getValuesFromGrid (grid2, Matrix2);
int m1columns_m2rows = Matrix1.GetLength(0);
int m1rows = Matrix1.GetLength(1);
int m2columns = Matrix2.GetLength(0);
for (int row = 0; row < m1rows; row++)
{
for (int column = 0; column < m2columns; column++)
{
double accumulator = 0;
for (int cell = 0; cell < m1columns_m2rows; cell++)
{
accumulator = Matrix1[cell, row] * Matrix2[column, cell];
}
Result[column, row] = accumulator;
}
initializeGrid(grid3, Result);
}
}
}
}
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
При запуске браузера, настройки успешно устанавливаются
Как сделать, так, чтобы при переключении на альбомную ориаентацию в игре, отключалась одна Panel, и запустилась другая? Можно ли со скрипта как...
Я повесил на кнопку <button type="submit" class="btn btn-primary btn-group-justified" id="save" onclick="confirm('Вы уверены что хотите сохранить?')">Сохранить</button>