Search code examples
c#wpf

Unable to reset ProgressBar


I am experimenting a behavior which makes me crazy.

I have a ProgressBar which represents the evolution of an import in database (in percents, from 0 to 100).

After the import is done (ProgressBar.Value = 100.0), I open a log window with a code which looks like this :

RadWindow window = new RadWindow()
{
    //Set some properties
};
window.Closed += Log_Closed;
window.ShowDialog();

After the RadWindow is closed, I want to reset the ProgressBar. As you can see I use the function Log_Closed whose code is bellow :

private void Log_Closed(object sender, EventArgs e)
{
    //pbImport.Value = pbImport.Minimum; (didn't work)
    pbImport.Value = 0;
}

Note : pbImport is my progress bar.

The instruction in Log_Closed has no effect.


Before instruction :

Before Instruction


After instruction :

After Instruction


Obviously, the progress bar is not updated in UI. I can't understand this. Thank you for your help.


Solution

  • Animations hold onto properties, in order to reset them in code, you have to remove the animation first so that the property is "released".

    See https://msdn.microsoft.com/en-us/library/aa970493%28v=vs.110%29.aspx for information on how to set a property after an animation in WPF.