none
想使ScrollViewer包含StackPanel该怎么写? RRS feed

  • 问题

  •     <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 该怎么写?

    2012年12月14日 6:36

答案

  • 你好,

    你可以试一下以下代码:

                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.

    2012年12月17日 10:39
    版主

全部回复

  • 你好,

    你可以试一下以下代码:

                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.

    2012年12月17日 10:39
    版主
  • sv.Content = sp;

    谢谢

    2012年12月19日 3:17