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 467309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:34:03+00:00 2026-05-12T23:34:03+00:00

In the following example, how can I get: the button to be disabled-grey the

  • 0

In the following example, how can I get:

  • the button to be “disabled-grey”
  • the message to say “working…”

while the work is being done, not after the work is done?

XAML:

<Window x:Class="TestIsEnabled8938.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <StackPanel Margin="10" HorizontalAlignment="Left">

        <Button x:Name="Button_Refresh" 
                    HorizontalAlignment="Left"  
                    DockPanel.Dock="Top" 
                    Content="Refresh" 
                    Click="Button_Refresh_Click" 
                    Height="25" 
                    Width="200"/>

        <TextBlock x:Name="Message" Text="Button is ready to click."/>
    </StackPanel>
</Window>

code-behind:

using System.Windows;
using System.Threading;

namespace TestIsEnabled8938
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void Button_Refresh_Click(object sender, RoutedEventArgs e)
        {
            Message.Text = "working...";
            Button_Refresh.IsEnabled = false;

            //do work
            Thread.Sleep(2000);

            Message.Text = "Button is ready to click again.";
            Button_Refresh.IsEnabled = true;
        }
    }
}

This doesn’t work either:

Dispatcher.Invoke(new Action(() => { Message.Text = "working..."; }));
Dispatcher.Invoke(new Action(() => { Button_Refresh.IsEnabled = false; }));

Answer:

Thanks Heinzi, this code works:

using System.Windows;
using System.Threading;
using System.ComponentModel;

namespace TestIsEnabled8938
{
    public partial class Window1 : Window
    {
        BackgroundWorker backgroundWorker;

        public Window1()
        {
            InitializeComponent();

            backgroundWorker = new BackgroundWorker();

            backgroundWorker.DoWork += (sender, args) =>
            {
                Thread.Sleep(3000);
            };

            backgroundWorker.RunWorkerCompleted += (sender, args) =>
            {
                Message.Text = "button is ready to click again";
                Button_Refresh.IsEnabled = true;
            };
        }

        private void Button_Refresh_Click(object sender, RoutedEventArgs e)
        {
            Message.Text = "working...";
            Button_Refresh.IsEnabled = false;
            backgroundWorker.RunWorkerAsync();
        }
    }
}
  • 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-05-12T23:34:04+00:00Added an answer on May 12, 2026 at 11:34 pm

    If you want the UI to update (and stay responsive) while your task is running, you need to use a separate thread, for example by using a BackgroundWorker.

    Code example (untested):

    BackgroundWorker bwButtonWorker;
    
    public Window1() {
        InitializeComponent();
    
        bwButtonWorker = new BackgroundWorker();
    
        bwButtonWorker.DoWork += (sender, args) => {
            // do your lengthy stuff here -- this happens in a separate thread
            Thread.Sleep(2000);
        }
    
        bwButtonWorker.RunWorkerCompleted += (sender, args) => {
            // this happens in the UI thread, so you can modify your UI elements here
            Message.Text = "Button is ready to click again.";
            Button_Refresh.IsEnabled = true;
        }
    }
    
    private void Button_Refresh_Click(object sender, RoutedEventArgs e)
    {
        Message.Text = "working...";
        Button_Refresh.IsEnabled = false;
        bwButtonWorker.RunWorkerAsync();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 242k
  • Answers 242k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The basic idea of doing something like this is called… May 13, 2026 at 7:33 am
  • Editorial Team
    Editorial Team added an answer If you have a valid XML file as template, you… May 13, 2026 at 7:33 am
  • Editorial Team
    Editorial Team added an answer You can use a name for the radio buttons and… May 13, 2026 at 7:33 am

Related Questions

The following RoutedCommand example works. However, the handling for the button which executes the
I am building a HTML scrubber basically an internal tool for scrubbing a problematic
Consider the following HTML. If I have a JSON reference to the <button> element,
I’m using Heather Solomon’s minimal publishing master page, I’ve got a simple feature with

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.