网格线不会在运行时显示我似乎可以看到我哪里出错了。这是一个 WPF 窗口应用程序。我只想使用 C# 代码生成列和行。任何想法为什么这不起作用?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace generator
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void CreateGrid()
{
ColumnDefinition myColum =new ColumnDefinition();
RowDefinition myRow = new RowDefinition();
ColumnDefinition myColum1 = new ColumnDefinition();
RowDefinition myRow1 = new RowDefinition();
Grid myGrid = new Grid();
myRow.Height = new GridLength(1, GridUnitType.Star);
myColum.Width = new GridLength(1, GridUnitType.Star);
myRow1.Height = new GridLength(1, GridUnitType.Star);
myColum1.Width = new GridLength(1, GridUnitType.Star);
myGrid.ColumnDefinitions.Add(myColum);
myGrid.RowDefinitions.Add(myRow);
myGrid.ColumnDefinitions.Add(myColum1);
myGrid.RowDefinitions.Add(myRow1);
myGrid.ShowGridLines = true;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
CreateGrid();
}
}
}