Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 矩形不';t显示在编程编码的界面中_C#_Wpf - Fatal编程技术网

C# 矩形不';t显示在编程编码的界面中

C# 矩形不';t显示在编程编码的界面中,c#,wpf,C#,Wpf,我正在通过代码构建一个界面,我需要在TextBlocks下添加两个TextBlocks和一个Rectangle,作为背景。使用“我的代码”时,会显示文本块,但矩形不会显示。我不知道是什么问题。你能帮忙吗 TextBlock question_textblock = new TextBlock(); question_textblock.Text = question; question_textblock.Margin = new Thickness(10, 103, 10, 0); quest

我正在通过代码构建一个界面,我需要在
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();

求解:将
矩形
作为第一个子项添加到
列表中\u网格
,如下图所示,如果它仍然没有显示,请选择其他颜色填充
矩形
。这应该是您想要的:

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

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);

list_grid.UpdateLayout();

那是wpf还是uwp!?问题解决了!非常感谢。颜色不是问题,我的背景已经是灰色的,矩形必须是白色的。