Hello stackoverflow社区,
我遇到麻烦让按钮和我的标签正确对齐,我想知道你们是否给我一些帮助!谢谢!
正如您所看到的那样,按钮有点偏离对齐。
// Testing Purposes
List<Item> headers = TestingClass.getHeaders();
// Organization of the grid structure
RowDefinition r1 = new RowDefinition();
grid_headers.RowDefinitions.Add(r1);
// Header for Label
ColumnDefinition cd0 = new ColumnDefinition();
Label label = new Label();
label.Content = "Label";
Grid.SetColumn(label, 0);
grid_headers.ColumnDefinitions.Add(cd0);
grid_headers.Children.Add(label);
// Header for Description
ColumnDefinition cd1 = new ColumnDefinition();
Label description = new Label();
Grid.SetColumn(description, 1);
description.Content = "Description";
grid_headers.ColumnDefinitions.Add(cd1);
grid_headers.Children.Add(description);
// Header for selection buttons
ColumnDefinition cd2 = new ColumnDefinition();
Label selection = new Label();
Grid.SetColumn(selection, 2);
selection.Content = "Selction";
grid_headers.ColumnDefinitions.Add(cd2);
grid_headers.Children.Add(selection);
// Loop through all of the headers
for (int i = 0; i < headers.Count; i++)
{
// Create button for choosing the header
Button btn = new Button();
btn.Content = "Select";
btn.Name = headers[i].Label;
btn.Width = 50;
btn.Height = 20;
btn.Padding = new Thickness(0.0, 0.0, 0.0, 0.0);
btn.Click += selectHeader;
RowDefinition rd = new RowDefinition();
grid_headers.RowDefinitions.Add(rd);
// Header for the labels
Label label_header = new Label();
label_header.Content = headers[i].Label;
Grid.SetColumn(label_header, 0);
Grid.SetRow(label_header, i+1); // Will always be i + 1 due to the first row for the main labels
grid_headers.Children.Add(label_header);
// Headers for the description
Label description_header = new Label();
description_header.Content = headers[i].Description;
Grid.SetColumn(description_header, 1);
Grid.SetRow(description_header, i + 1); // Will always be i + 1 due to the first row for the main labels
grid_headers.Children.Add(description_header);
// Button for selecting which header
Grid.SetColumn(btn, 2);
Grid.SetRow(btn, i + 1); // Will always be i + 1 due to the first row for the main labels
grid_headers.Children.Add(btn);
}
在我的代码中,我动态生成了网格。
感谢您的帮助,我非常感谢。