Search code examples
c#windows-phone-7progress-bar

How to show ProgressBar control while a page is loading?


I have WP7 application with several pages. When a user navigates through them it takes some time to load information. So before showing him/her the page I'd like to show “Loading…” message. I created progress bar and placed it on the page:

    <StackPanel x:Name="progressBarMain" Grid.Row="1" Grid.ColumnSpan="2" Visibility="Collapsed">
        <TextBlock Text="Loading..." HorizontalAlignment="Center" VerticalAlignment="Center" />
        <ProgressBar Margin="10" Height="30" IsIndeterminate="True"/>
    </StackPanel>

And I'm trying to show it (and hide everything else) in the page's constructor, and hide it (and show everything else) in Page.Loaded handler.

    public SomePage()
    {
        InitializeComponent();

        Loaded +=OnSomePageLoaded;
        progressBarMain.Visibility = Visibility.Visible;
        ContentPanel.Visibility = Visibility.Collapsed;
    }

    private void OnSomePageLoaded(object sender, RoutedEventArgs e)
    {
        progressBarMain.Visibility = Visibility.Collapsed;
        ContentPanel.Visibility = Visibility.Visible;
    }

But it doesn’t' work. Any ideas? Thank you!


Solution

  • Alex demonstrates showing a progress bar while the app is starting up here.

    Creating a Splash Screen with a progress bar for WP7 applications. - Alex Yakhnin's Blog