积极答复者
想使ScrollViewer包含StackPanel该怎么写?

问题
-
<Grid x:Name="LayoutRoot" Background="White">
<ScrollViewer Width="178" Background="Black" HorizontalAlignment="Left">
<StackPanel x:Name="b"></StackPanel>
</ScrollViewer>
</Grid>改成后台怎么写?
也就是说:
ScrollViewer a = new ScrollViewer();
StackPanel b = new StackPanel();
我要使b是a的Children 该怎么写?
答案
-
你好,
你可以试一下以下代码:
ScrollViewer sv = new ScrollViewer(); StackPanel sp = new StackPanel(); for (int i = 1; i < 200; i++) { TextBox tb = new TextBox(); tb.Name="textbox"+i.ToString(); tb.Text = tb.Name; sp.Children.Add(tb); } //TextBox tb = new TextBox(); //sp.Children.Add(tb); sv.Content = sp; LayoutRoot.Children.Add(sv);
结果:
Mark Yu - MSFT
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 iwpfModerator 2012年12月20日 1:18
全部回复
-
你好,
你可以试一下以下代码:
ScrollViewer sv = new ScrollViewer(); StackPanel sp = new StackPanel(); for (int i = 1; i < 200; i++) { TextBox tb = new TextBox(); tb.Name="textbox"+i.ToString(); tb.Text = tb.Name; sp.Children.Add(tb); } //TextBox tb = new TextBox(); //sp.Children.Add(tb); sv.Content = sp; LayoutRoot.Children.Add(sv);
结果:
Mark Yu - MSFT
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 iwpfModerator 2012年12月20日 1:18