[Q] WP7 - ProgressBar sample?

GFR_2009

Member
Oct 9, 2009
37
0
0
Hi there,

I'm a little bit stuck with a page transition.

In my app, I select a name from a listbox which is located in another page (Page 2)

Once the name is selected from the listbox (in page 2) it automatically returns to the calling page.

Problem is that during the transition, in the OnNavigatedTo event of Page 1, it fires a query which takes some time and the transition is freezed during that time.

How can I add a ProgressBar to warn the user?

If possible, I'd like to stay as "official" as possible, so my idea is to use the standard ProgressBar supllied in the RTW.

I tried many searches and found nothing close to a workable sample on this.

Any help is much apprecitated in advance!
 

williammel

Senior Member
Nov 27, 2010
66
3
0
Hi there,

I'm a little bit stuck with a page transition.

In my app, I select a name from a listbox which is located in another page (Page 2)

Once the name is selected from the listbox (in page 2) it automatically returns to the calling page.

Problem is that during the transition, in the OnNavigatedTo event of Page 1, it fires a query which takes some time and the transition is freezed during that time.

How can I add a ProgressBar to warn the user?

If possible, I'd like to stay as "official" as possible, so my idea is to use the standard ProgressBar supllied in the RTW.

I tried many searches and found nothing close to a workable sample on this.

Any help is much apprecitated in advance!

If you're not already using the PerformanceProgressBar, you should be.

http://www.jeff.wilcox.name/2010/08/performanceprogressbar/

It's pretty much 'plug&play'.

There are 2 ideas which you could try to fix your problem.
An idea that you could try is using a DispatcherTimer. A timer will allow the function to finish loading, while creating an event which will fire to display the progress bar. When the page has finished loading, (say 1 sec) your timer could tick, and do whatever work you need done. Another solution would be to add a Loaded event on the page. This would allow you to run some code once the page is fully loaded. This is probably the best design. To do that, you'd need some code like this:

Code:
public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            ProgressBar pb = new ProgressBar();
            pb.Style = PhoneApplicationService.Current.State["PerformanceProgressBar"] as Style;
            pb.IsIndeterminate = true;

//add it onto the page, since it wasn't done in XAML.
            LayoutRoot.Children.Add(pb);
        }
Note that you can still create the ProgressBar in XAML, it was just easier to only show 1 file.
 
Last edited:
  • Like
Reactions: GFR_2009