I have window with a lot of items and tools, what I want to do, and ask about, is how can I show a progress bar while the window is loading with a WPF main or child window?
-
2What exactly is blocking you from doing exactly that? – O. R. Mapper Nov 27 '13 at 12:04
-
a simple way is just try to calculate the loading time and create a new wpf window with a loading bar and in code behind manage a timer of nearby time to the loading time and display it then. – Neel Bhasin Nov 27 '13 at 12:04
-
If you're looking for a really easy solution without coding (looks like to me), you can also choose an image and set it's build action to splash screen. No answer from me though, as you asked for something else. – Akku Nov 27 '13 at 12:06
-
Sorry, but this is the first time I try to using progress bar, please can you give me an example, will be so thankful for you – YoMo Nov 27 '13 at 12:10
2 Answers
You could try this link:
http://bensprogrammingwork.blogspot.com.br/2012/01/progressbar-in-wpf.html
Might be helpful, I could try to explain more but I don't really know what's your struggle.

- 161
- 2
- 13
It is pointless attempting to do that with WPF because by the time the Framework
has loaded your application and you are able to display a Window
with a progress bar, the MainWindow.xaml
page will have already loaded.
There is a way to display a static image before the application has fully loaded, but you cannot animate any part of it. You can find out how to do that in the How to: Add a Splash Screen to a WPF Application page on MSDN.
If you definitely want a loading animation upon start up, you will have to wait until the application has finished loading and then 'pretend' to the users that it is still loading with your animation... pretty pointless I think you would agree.
Even so, if you are determined to go down that path, you can find a working example of a loading animation in the A Simple WPF Loading Animation page on the ElegantCode website.
UPDATE >>>
Oh sorry, I didn't realise that this was not just for the start up Window
. No, you can only use the splash screen upon application start up. The problem that you will find when displaying an animation when a Window
is loading is that (generally) the Window
is loaded using the UI thread. As your animation will also be using the UI thread, you will find that it probably won't run smoothly because the UI thread is busy loading and initialising the Window
. You can still try using the last link that I provided for this, but don't expect too much.
-
I tried Splash Screen now, but it's using for application start up, can I use it for when specific windows loaded? that's what I want Sheridan. – YoMo Nov 27 '13 at 12:48
-
Sheridan, Thank you so much for your time, I'm confused now and I don't know what's the best way to do what I want to do, please can you give me your opinion – YoMo Nov 27 '13 at 19:56
-
The last line in my answer sums up my opinion: *You can still try... but don't expect too much.* It might work a bit, but it *will* freeze when the `Window` is loading. You could just have a simple text animation done with a `DispatcherTimer` updating a `TextBlock` at regular intervals, but again, that would probably freeze too. Try it and see... you might get lucky. – Sheridan Nov 27 '13 at 21:41
-
Now, I'm tring to use Backgrounworker, but how can I load the window from another window? http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2 – YoMo Nov 27 '13 at 22:57
-
Unfortunately, I tried use loading animation, Telerik busyindecator and backgroundworker but all these make the window frozen. Is it possible that there is no solution !!! – YoMo Nov 28 '13 at 09:09
-
@YoMo, that's what he told you already. WPF initializes from top down, so you have to be really clever or really lucky. – Gayot Fow Nov 28 '13 at 16:51