我正在通过代码构建界面,我需要在TextBlocks
下添加两个Rectangle
和一个TextBlocks
作为背景。我的代码显示TextBlocks
但Rectangle
没有显示。我不知道问题是什么。你能帮忙吗?
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();
答案 0 :(得分:0)
要解决:将Rectangle
作为第一个孩子添加到list_grid
,如下所示,如果仍未显示,请选择其他颜色来填充{{ 1}}。这应该是你想要的:
Rectangle