矩形不会以编程编码的界面显示

时间:2016-01-20 16:32:35

标签: c# wpf

我正在通过代码构建界面,我需要在TextBlocks下添加两个Rectangle和一个TextBlocks作为背景。我的代码显示TextBlocksRectangle没有显示。我不知道问题是什么。你能帮忙吗?

TextBlock question_textblock = new TextBlock();
question_textblock.Text = question;
question_textblock.Margin = new Thickness(10, 103, 10, 0);
question_textblock.FontWeight = FontWeights.Bold;
list_grid.Children.Add(question_textblock);

TextBlock answer_textblock = new TextBlock();
answer_textblock.Text = question;
answer_textblock.Margin = new Thickness(10, 124, 10, 0);
list_grid.Children.Add(answer_textblock);

Rectangle rect = new Rectangle();
rect.Height = 69;
rect.Fill = new SolidColorBrush(Color.FromArgb(0, 0, 0, 1));
rect.Margin = new Thickness(0, 95, 0, 0);
rect.VerticalAlignment = VerticalAlignment.Top;
list_grid.Children.Add(rect);

list_grid.UpdateLayout();

1 个答案:

答案 0 :(得分:0)

要解决:将Rectangle作为第一个孩子添加到list_grid,如下所示,如果仍未显示,请选择其他颜色来填充{{ 1}}。这应该是你想要的:

Rectangle