Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8734491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:51:03+00:00 2026-06-13T09:51:03+00:00

I have a WPF application (Window 1) with a ScrollViewer on it. I have

  • 0

I have a WPF application (Window 1) with a ScrollViewer on it. I have a second window that is apart of the same WPF application, that has a button on it.

When I click the button on the second window, I want it to add an item to the ScrollViewer on the first window.

How can I accomplish this? Sorry if this is vague, I’m not sure how to ask this question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:51:04+00:00Added an answer on June 13, 2026 at 9:51 am

    First, you’ll need a DispatcherTimer and you’ll have to use StackPanel instead of Grid. You’ll also need to declare a public static bool on Window1. Then, when the button on Window2 is clicked, the bool is set to True which means to execute a void that will add the object to the StackPanel or the Scroll Viewer

    XAML

    Window1.xaml

    First, you will need to change Grid to StackPanel. Assuming that you have a ScrollViewer with the name scrollViewer1, and Margin = "37,36,58,36", You should try the following

    Change the following

    <Grid>
        <ScrollViewer Margin="37,36,58,36" Name="scrollViewer1" />
    </Grid>
    

    to

    <StackPanel x:Name="stackPanel">
        <ScrollViewer Margin="37,36,58,36" Name="scrollViewer1" />
    </StackPanel>
    

    So that you would be able to use a StackPanel instead of a Grid of a name stackPanel
     


    C#

    Window1.xaml

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    
    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for Window1.xaml
        /// </summary>
        public partial class Window1 : Window
        {
            public static bool AddItem = false; //This must be public and static so that it can be called from your second Window
            public Window1()
            {
                InitializeComponent();
            }
            public void AddToScrollViewer()
            {
                Button _Object = new Button(); //Create a new object, change button to the UIElement you would like to be
                stackPanel.Children.Add(_Object); //Add the UIElement to the StackPanel
            }
    
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); //Initialize a new timer object
                dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); //Link the Tick event with dispatcherTimer_Tick
                dispatcherTimer.Interval = new TimeSpan(0, 0, 1); //Set the Timer Interval
                dispatcherTimer.Start(); //Start the Timer
            }
    
            private void dispatcherTimer_Tick(object sender, EventArgs e)
            {
                if (AddItem)
                {
                    AddItem = false;
                    AddToScrollViewer();
                }
            }
        }
    }
    

    Window2.xaml

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;
    
    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for Window2.xaml
        /// </summary>
        public partial class Window2 : Window
        {
            public Window2()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                Window1.AddItem = true;
            }
        }
    }
    

    Thanks,

    I hope you find this helpful 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF application that has several modal window used for various purposes.
I have a WPF application that has a main window. In that I have
I have a WPF application that contains some Window s with few UserControl s
I have a wpf application with a simple window that shows a text in
I have a WPF application with two DataGrids that share the same ItemsSource. When
I have a WPF application that uses a custom window frame. My problem is
I have a WPF application. In one window there is a combobox..and I want
I have a WPF application with one window. This window has one image and
Say I have a WPF application with a button. In the buttom click event,
I have a WPF application that is made up of a window containing a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.