[英]Dynamic grid within a scrollviewer
I have a grid which contains dynamically created pairs of textblocks and buttons. 我有一个网格,其中包含动态创建的成对的文本块和按钮。 I can continue to add these objects infinitely but after they fill the grid, the new pairs are not visible. 我可以继续无限添加这些对象,但是在它们填满网格之后,新的对将不可见。
I have tried to solve this by putting the grid inside a scrollviewer and each time a new pair is added, increasing the height/maxheight of both the grid and the scrollviewer. 我试图通过将网格放在scrollviewer中来解决此问题,每次添加新对时,都增加了网格和scrollviewer的高度/最大高度。 But I still cannot see the new elements after the screen is filled. 但是,在屏幕填充后,我仍然看不到新元素。
This is from my .xaml file 这是来自我的.xaml文件
<ScrollViewer x:Name="ContentScroll" Grid.Row="1">
<Grid x:Name="ContentPanel" HorizontalAlignment="Left" Height="577" Grid.Row="1" VerticalAlignment="Top" Width="470"> </Grid>
</ScrollViewer>
and this is from my .xaml.cs file 这是来自我的.xaml.cs文件
List<TextBlock> textblock_list = new List<TextBlock>();
List<Button> button_list = new List<Button>();
for(int i = 0; i < classlist.Count(); i++)
{
TextBlock tb = new TextBlock();
tb = SetTextBlock(tb, i);
tb.Text = classlist[i].name;
textblock_list.Add(tb);
ContentPanel.Children.Add(textblock_list[i]);
Button bt = new Button();
bt = SetButton(bt, i);
button_list.Add(bt);
ContentPanel.Children.Add(button_list[i]);
Grid.SetColumn(bt, i);
}
Any thoughts on a solution? 对解决方案有什么想法吗? Thanks in advance. 提前致谢。
尝试从网格中删除Height="577"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.