How should I indicate progress in a Windows Phone

2019-06-12 09:45发布

问题:

I have a couple of operations in my WP7 app that I need to indicate to the end user as taking a while.

In the Android world I would call the ProgressDialog, which causes the screen to dim and the phone-specific spinner animation and whatever message I want in the middle of the screen.

Some searching indicates that the proper way to do this in Windows Phone 7 (Mango, anyway) is to use the ProgressIndicator, so I went down that road.

The problem is that in my app I do not want to see the system tray. I am hiding it in the XAML and I want to use the entire 800x480, and as near as I can tell ProgressIndicator doesn't fly unless there's a visible SystemTray.

Is there a way to use ProgressIndicator without SystemTray? (i.e., it shows up, translucently, across the top of the app and then goes away) Failing that, are there any other predefined and established ways of indicating something like a ProgressDialog in WP7?

回答1:

You can simply use the progress bar as shown by KraZ88.

Simply drag the 'ProgressBar' control from the Toolbox to your page. If you can see this then right-click on the toolbox and select 'Choose Items'. The Next dialog box shows you a list of controls which you can use but haven't been using! :). Check on the 'ProgressBar' control there and click on OK.

Now you will be be able to see 'ProgressBar'.

Now, you have two options with Windows Phone 7.1:

  • Show the user an 'indeterminate' view of progress. Meaning, he may not know much of the work is left but he knows that work is in progress.

This is achieved by simply setting the Visibility property to Collapsed initially and setting it to Visible when your work starts. Next, set IsIndeterminate = true. Your work is half done. Now just set progressBar1.Value += progressBar1.SmallChange;

  • The next way is to show the user an accurate view of the progress with the help of calculations. Which means recalculating the progress left after every unit of iteration of your work.

To achieve this, you need to set IsIndeterminate = false and then set the maximum and minimum value of the progress bar according to your dependencies and then just reset the value of the progress bar after every iteration. Here's a example to begin with:

ProgressBar1.Maximum=array.Length;
ProgressBar1.Minimum=0;

for(int i =0;i<array.Lenght;i++)
{//some logic
progressBar1.Value +=1;
}


回答2:

Coding4Fun has a library with tools for Windows Phone 7. That kit contains the ProgressOverlay-control. Basically, when you add a dll-reference to it and add a reference in your XAML-file, you can do something like this:

<Controls:ProgressOverlay Name="progressOverlay" Margin="0" >
    <Controls:ProgressOverlay.Content>
        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
            <ProgressBar IsIndeterminate="true" x:Name="customIndeterminateProgressBar" Style="{StaticResource CustomIndeterminateProgressBar}" />
        </StackPanel>
    </Controls:ProgressOverlay.Content>
</Controls:ProgressOverlay>

This puts an overlay on your layout and in the middle of the screen the ProgressBar is shown. You can add controls yourself in the StackPanel if you want. For example, a TextBlock with the Text 'Loading...'. You can find the download on CodePlex.

Hope this helps!



回答3:

You can simple use the ProgessBar without SystemTray in this way:

<ProgressBar IsEnabled="True" Height="5" Width="480"/>