question

essamce avatar image
0 Votes"
essamce asked ·

adding stacked pages in xaml at runtime

hi
what is the appropriate way to show pages vertically (something like MS word...) and adding pages at run time?
thanks in advance.

windows-wpf
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AlexLi-MSFT avatar image
1 Vote"
AlexLi-MSFT answered ·

Welcome to our Microsoft Q&A platform!

I made an example,you can use button to add random color pages。

xaml:

   <ScrollViewer x:Name="scrolls" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" >
             <ScrollViewer.Content>
                 <StackPanel Name="mystackpanel" ScrollViewer.VerticalScrollBarVisibility="Auto">
                     <Button Content="btn1" Click="Button_Click"/>
                 </StackPanel>
             </ScrollViewer.Content>
         </ScrollViewer>

C#

  public partial class MainWindow : Window
     {
         int i = 1;
         public MainWindow()
         {
             InitializeComponent();
         }
    
         private void Button_Click(object sender, RoutedEventArgs e)
         {
             Frame frame = new Frame();
             Page page = new Page();
             Random random = new Random();
             page.Background = new SolidColorBrush(Color.FromRgb((byte)random.Next(0, 255), (byte)random.Next(0, 255), (byte)random.Next(0, 255)));
             page.Height = 200;
             page.Name = "Page" + i.ToString();
             frame.Content = page;
             mystackpanel.Children.Add(frame);
             i += 1;
         }
     }


Thanks.

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

hi @AlexLi-MSFT, do u know how to bind a page property to the page index as StackPanel Child?

0 Votes 0 ·