[英]c# WPF How to show my progressbar while the xaml window is loading?
i am trying to display my Progress bar while my WPF window is loading.我正在尝试显示我的进度条,而我的 WPF window 正在加载。 I succeeded to fill the progressbar but it's not showing Refer to the screenshots to see what i mean showingProgressBar but when the windows has loaded completly , it's showing when every components of the window is loaded.我成功填充了进度条,但它没有显示 请参阅屏幕截图,看看我的意思是显示ProgressBar 但是当 windows 已完全加载时,它会显示 window 的每个组件何时加载。 It's doing the right behavior i want when I put some MessageBox at the end of every method to load components like this screenshot and this screenshot , so my question is How to show my progressbar while the xaml window is loading?当我在每个方法的末尾放置一些 MessageBox 来加载像这个屏幕截图和这个屏幕截图这样的组件时,它正在做我想要的正确行为,所以我的问题是如何在 xaml window 正在加载时显示我的进度条? any help would be appreciated.任何帮助,将不胜感激。
Thanks in advance提前致谢
private void DoWorkButton_Click(object sender, RoutedEventArgs e)
{
testProgressBar.Visibility = Visibility.Visible;
ProgressTextblock.Visibility = Visibility.Visible;
BackgroundWorker worker = new BackgroundWorker();
worker.RunWorkerCompleted += worker_RunWorkerCompleted;
worker.WorkerReportsProgress = true;
worker.DoWork += worker_doWork;
worker.ProgressChanged += worker_ProgressChanged;
worker.RunWorkerAsync();
}
private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
testProgressBar.Value = e.ProgressPercentage;
ProgressTextblock.Text = (string)e.UserState;
}
private void worker_doWork(object sender, DoWorkEventArgs e)
{
var worker = sender as BackgroundWorker;
worker.ReportProgress(0, String.Format("Chargement des composants de la fenetre"));
}
private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
MessageBox.Show("Fenetre chargée normalement");
}
I fill the Progress bar like this in every method which is called to load the the window我在调用加载 window 的每个方法中都像这样填充进度条
It's how you've set the order, I think ordering it like this should solve it:这就是您设置订单的方式,我认为像这样订购它应该可以解决它:
private void DoWorkButton_Click(object sender, RoutedEventArgs e)
{
testProgressBar.Visibility = Visibility.Visible;
ProgressTextblock.Visibility = Visibility.Visible;
BackgroundWorker worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.DoWork += worker_doWork;
worker.ProgressChanged += worker_ProgressChanged;
worker.RunWorkerCompleted += worker_RunWorkerCompleted;
worker.RunWorkerAsync();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.