3
Hello, I saw several examples on the internet of progressiBar in WPF , but none works.
It appears no longer fills the values, in fact it fills the values only after running the initial method where it is called.
Source code:
public partial class Apresentacao_ProgressBar : Window
{
private BackgroundWorker backgroundWorker1 = new BackgroundWorker();
public Apresentacao_ProgressBar()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Form1_Shown);
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
}
void Form1_Shown(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i <= 100; i++)
{
backgroundWorker1.ReportProgress(i);
System.Threading.Thread.Sleep(100);
}
}
void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
PBar.Value = e.ProgressPercentage;
}
}
The event
Form1_Shown
is being called when the form is opened?– MurariAlex
The event is being called yes.
– Verin