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

  • SEARCH
  • Home
  • 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 9004307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:52:07+00:00 2026-06-16T00:52:07+00:00

I have a WPF/C# program with several classes, and the MainWindow.cs class has user

  • 0

I have a WPF/C# program with several classes, and the MainWindow.cs class has user controls which I’d like to update with the status of the computation occurring inside other classes. After googling around and borrowing from examples, I figured out how to set up an Event inside the other class, and invoking it when something changed. Then as long as the main class has a handler tied that event, I could appropriately update UI stuff (status bars, etc). Below is a stripped-down version of what I’m doing:

    namespace Program
     {
     public partial class MainWindow : Window
     {
          public void SetUpHandler()
          {
               TestA.WorkerProgressThingie += new    ProgressChangedEventHandler(TestA_ProgressChanged);
          }
          void TestA_ProgressChanged(object sender, ProgressChangedEventArgs e)
          {
               progressBar1.Value = e.ProgressPercentage
          }

     }




    public class TestA    
{
    public static event ProgressChangedEventHandler WorkerProgressThingie;

    public static void SomeFunction()
    {   
        int value = 0;         

        //...(some boring code that does something here)

        ProgressChangedEventArgs e = new ProgressChangedEventArgs(value, null);            

        if (WorkerProgressThingie != null)
            WorkerProgressThingie.Invoke(null, e)
    }


}
}
  • Is there not a way to simply call the progressBar property from the other class? (i.e. MainWindow.progressBar.Value)?
  • What is the purpose of the “object sender” parameter when I invoke the event, and how is it supposed to be used normally? The examples I see always use ‘null’.

Thanks!

  • 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-16T00:52:08+00:00Added an answer on June 16, 2026 at 12:52 am

    1) Yes, you can access any part of any class if it is declared public. In this case, you could declare the progressBar control as public, and anything that has a reference to class MainWindow can fiddle with it. HOWEVER, this would be pretty poor practice. Instead, you could bind to some ‘value’ which updates in relation to the current progress of the activity and let the MainWindow class worry about how it represents that change (in this case by updating a ProgressBar),

    2) object sender in all events is meant to be a reference to the object which raised the event, so the event consumer knows where the event came from. Using null is also poor practice IMO, and in general, an object which raises an event should do so like;

    SomeEvent(this, someEventArgs);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here you have a simple WPF program: <!-- Updater.xaml --> <Window x:Class=Update.Updater xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
I have WPF Application where I have One main form and other user controls
I have WPF Form which has many buttons with the same code. Appearance of
I am writing a WPF program in C# in which I have a ListView
I have a wpf program in c# that has a combobox with various colors
I have a WPF program with two listviews which display information from two different
I have a WPF assembly in which I would like to embed five icons
I have a WPF program that produces several DataGrids. I have added capability to
I have created a program that subscribes to WPF's touch events. Everything has been
The Situation I have a WPF program that I want to print several documents

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.