WPF Groupbox Content RowDefinition

Site Index




GroupBox[] z_groupBox = new GroupBox[25];
Grid[] z_Grid1 = new Grid[25];
Grid[] z_Grid21 = new Grid[25];
Grid[] z_Grid22 = new Grid[25];
TextBlock[] z_textBlock1 = new TextBlock[25];
TextBlock[] z_textBlock2 = new TextBlock[25];
TextBlock[] z_textBlock3 = new TextBlock[25];
TextBlock[] z_textBlock4 = new TextBlock[25];

private void SetChart()
{
for (int idx=0;idx<25;idx++)
{
int w_x = idx % 5;
int w_y = idx / 5;
z_groupBox[idx] = new GroupBox();
grid_main.Children.Add(z_groupBox[idx]);
z_groupBox[idx].SetValue(Grid.RowProperty,w_y);
z_groupBox[idx].SetValue(Grid.ColumnProperty,w_x);
z_groupBox[idx].Background = new SolidColorBrush(Colors.Blue);

z_Grid1[idx] = new Grid();
z_groupBox[idx].Content = z_Grid1[idx];
//*******************
// Grid1
//*******************
RowDefinition w_row1 = new RowDefinition();
RowDefinition w_row2 = new RowDefinition();
w_row1.Height = new GridLength(30,GridUnitType.Pixel);
w_row2.Height = new GridLength(1, GridUnitType.Star);
z_Grid1[idx].RowDefinitions.Add(w_row1);
z_Grid1[idx].RowDefinitions.Add(w_row2);

z_Grid21[idx] = new Grid();
z_Grid22[idx] = new Grid();
z_Grid1[idx].Children.Add(z_Grid21[idx]);
z_Grid1[idx].Children.Add(z_Grid22[idx]);

z_Grid21[idx].SetValue(Grid.RowProperty, 0);
z_Grid22[idx].SetValue(Grid.RowProperty, 1);

z_Grid21[idx].Background = new SolidColorBrush(Colors.AliceBlue);
z_Grid22[idx].Background = new SolidColorBrush(Colors.Aqua);
//*******************
// Grid21
//*******************
ColumnDefinition w_col1 = new ColumnDefinition();
ColumnDefinition w_col2 = new ColumnDefinition();
ColumnDefinition w_col3 = new ColumnDefinition();
ColumnDefinition w_col4 = new ColumnDefinition();
w_col1.Width = new GridLength(20, GridUnitType.Pixel);
w_col2.Width = new GridLength(20, GridUnitType.Pixel);
w_col3.Width = new GridLength(20, GridUnitType.Pixel);
w_col4.Width = new GridLength(1, GridUnitType.Star);
z_Grid21[idx].ColumnDefinitions.Add(w_col1);
z_Grid21[idx].ColumnDefinitions.Add(w_col2);
z_Grid21[idx].ColumnDefinitions.Add(w_col3);
z_Grid21[idx].ColumnDefinitions.Add(w_col4);

z_textBlock1[idx] = new TextBlock();
z_textBlock2[idx] = new TextBlock();
z_textBlock3[idx] = new TextBlock();
z_textBlock4[idx] = new TextBlock();
z_Grid21[idx].Children.Add(z_textBlock1[idx]);
z_Grid21[idx].Children.Add(z_textBlock2[idx]);
z_Grid21[idx].Children.Add(z_textBlock3[idx]);
z_Grid21[idx].Children.Add(z_textBlock4[idx]);

z_textBlock1[idx].SetValue(Grid.ColumnProperty, 0);
z_textBlock2[idx].SetValue(Grid.ColumnProperty, 1);
z_textBlock3[idx].SetValue(Grid.ColumnProperty, 2);
z_textBlock4[idx].SetValue(Grid.ColumnProperty, 3);
z_textBlock1[idx].Background = new SolidColorBrush(Colors.Green);
z_textBlock2[idx].Background = new SolidColorBrush(Colors.GreenYellow);
z_textBlock3[idx].Background = new SolidColorBrush(Colors.Green);
z_textBlock4[idx].Background = new SolidColorBrush(Colors.GreenYellow);
}
}

TextBlock複数行表示と行間隔調整




z_textBlock4[idx].LineStackingStrategy = LineStackingStrategy.BlockLineHeight;
z_textBlock4[idx].TextWrapping = TextWrapping.Wrap;
z_textBlock4[idx].LineHeight = 14;




AX