WPF矩阵显示问题

WPF矩阵显示问题,wpf,matrix,Wpf,Matrix,我想制作一个日程表应用程序,其中我需要一个包含所有员工姓名的列,第一行应该是当前周日期,每天7列,其余的应该是工作时间+总小时数的最后2列。 我有一个27x10位的矩阵 我需要在WPF GUI中表示这个矩阵。 其想法是,用户可以通过单击相关按钮来更改特定单元格的内容,该按钮表示矩阵中的特定单元格,向其添加数据并将其保存到sql数据库中 我已经考虑过使用网格,但由于GUI设计问题,不可能使用它 public void DrawButtons() { int dateCou

我想制作一个日程表应用程序,其中我需要一个包含所有员工姓名的列,第一行应该是当前周日期,每天7列,其余的应该是工作时间+总小时数的最后2列。 我有一个27x10位的矩阵 我需要在WPF GUI中表示这个矩阵。 其想法是,用户可以通过单击相关按钮来更改特定单元格的内容,该按钮表示矩阵中的特定单元格,向其添加数据并将其保存到sql数据库中

我已经考虑过使用网格,但由于GUI设计问题,不可能使用它

 public void DrawButtons()
    {
        int dateCounter = 0;
        for (int i = 0; i <= 26; i++)
        {
            myGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
            myGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) });
            for (int j = 0; j <= 9; j++)
            {
                dateCounter++;
                if (Matrix[i, j] == 3)
                {
                    Button cellButtons = new Button
                    {
                        Height = 20,
                        Width = 50,
                        Background = new SolidColorBrush(Colors.AliceBlue),
                        Foreground = new SolidColorBrush(Colors.Black),
                        IsEnabled = true,
                        Content = "Q",
                        HorizontalContentAlignment = HorizontalAlignment.Center,
                        VerticalContentAlignment = VerticalAlignment.Center,

                    };
                    cellButtons.SetValue(Grid.RowProperty, i);
                    cellButtons.SetValue(Grid.ColumnProperty, j);
                    myGrid.Children.Add(cellButtons);

                }
                else if (Matrix[i, j] == 2)
                {

                    Button columnHeaderButton = new Button
                    {

                        Height = 20,
                        Width = 50,
                        Background = new SolidColorBrush(Colors.Azure),
                        Foreground = new SolidColorBrush(Colors.Black),
                        IsEnabled = true,
                        Content = "X",
                        HorizontalContentAlignment = HorizontalAlignment.Center,
                        VerticalContentAlignment = VerticalAlignment.Center,

                    };
                    // Need to add weeks
                    columnHeaderButton.SetValue(Grid.RowProperty, i);
                    columnHeaderButton.SetValue(Grid.ColumnProperty, j);
                    myGrid.Children.Add(columnHeaderButton);
                //    ColumnHeaderButtons.Add(columnHeaderButton);



                }

                else if (Matrix[i, j] == 6)
                {

                    Button rowHeaderButton = new Button
                    {

                        Height = 20,
                        Width = 50,
                        Background = new SolidColorBrush(Colors.Azure),
                        Foreground = new SolidColorBrush(Colors.Black),
                        IsEnabled = true,
                        Content = "X",
                        HorizontalContentAlignment = HorizontalAlignment.Center,
                        VerticalContentAlignment = VerticalAlignment.Center,

                    };
                    //Add shift
                    rowHeaderButton.SetValue(Grid.RowProperty, i);
                    rowHeaderButton.SetValue(Grid.ColumnProperty, j);
                    myGrid.Children.Add(rowHeaderButton);

                }

                else if (Matrix[i, j] == 1)
                {

                    Button columnHeaderButton = new Button
                    {

                        Height = 20,
                        Width = 50,
                        Background = new SolidColorBrush(Colors.Azure),
                        Foreground = new SolidColorBrush(Colors.Black),
                        IsEnabled = true,
                        Content = "Name",
                        HorizontalContentAlignment = HorizontalAlignment.Left,
                        VerticalContentAlignment = VerticalAlignment.Top,

                    };

                    columnHeaderButton.SetValue(Grid.RowProperty, i);
                    columnHeaderButton.SetValue(Grid.ColumnProperty, j);
                    myGrid.Children.Add(columnHeaderButton);


                }
                else if (Matrix[i, j] == 9)
                {

                    Button columnHeaderButton = new Button
                    {

                        Height = 20,
                        Width = 50,
                        Background = new SolidColorBrush(Colors.Azure),
                        Foreground = new SolidColorBrush(Colors.Black),
                        IsEnabled = true,
                        Content = "M",
                        HorizontalContentAlignment = HorizontalAlignment.Center,
                        VerticalContentAlignment = VerticalAlignment.Center,

                    };
                  columnHeaderButton.SetValue(Grid.RowProperty, i);
                  columnHeaderButton.SetValue(Grid.ColumnProperty, j);
                  myGrid.Children.Add(columnHeaderButton);
                }
    public int[,] Matrix =
    { 
        {4, 2, 2, 2, 2, 2, 2, 2, 7, 8},
        {5, 3, 3, 3, 3, 3, 3, 3, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},
        {1, 6, 6, 6, 6, 6, 6, 6, 9,10},


    };

你的问题是什么?删除所有可怕的代码并使用适当的数据绑定。WPF不是winforms。