Windows Phone 8.1 ProgressBar 进度条

network | | 访问(41)
<StackPanel>
    <TextBlock Text="选择ProgressBar的类型:" FontSize="20" />
    <RadioButton Content="Determinate类型" Height="71" Name="radioButton1" GroupName="Type"/>
    <RadioButton Content="Indeterminate类型" Height="71" Name="radioButton2" GroupName="Type" IsChecked="True" />
    <Button Content="启动ProgressBar" Height="72" x:Name="begin"  Click="begin_Click" />
    <Button Content="取消ProgressBar" Height="72" x:Name="cancel"  Click="cancel_Click" />
    <ProgressBar x:Name="progressBar1" IsIndeterminate="true"  />
</StackPanel>
public sealed partial class MainPage: Page {

    public MainPage() {
        this.InitializeComponent();
        progressBar1.Visibility = Visibility.Collapsed;
    }

    private void begin_Click(object sender, RoutedEventArgs e) {
        progressBar1.Visibility = Visibility.Visible;

        if (radioButton1.IsChecked == true) {
            progressBar1.IsIndeterminate = false;
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += timer_Tick;
            timer.Start();
        } else {
            progressBar1.Value = 0;
            progressBar1.IsIndeterminate = true;

        }
    }
    async void timer_Tick(object sender, object e) {
        if (progressBar1.Value < 100) {
            progressBar1.Value += 10;
        } else { (sender as DispatcherTimer).Tick -= timer_Tick; (sender as DispatcherTimer).Stop();
            await new MessageDialog("进度完成").ShowAsync();
        }

    }
    private void cancel_Click(object sender, RoutedEventArgs e) {
        progressBar1.Visibility = Visibility.Collapsed;
    }

    protected override void OnNavigatedTo(NavigationEventArgs e) {}
}