【问题标题】:Windows Phone 8 ProgressbarWindows Phone 8 进度条
【发布时间】:2015-01-19 21:48:25
【问题描述】:

我正在制作一个问答游戏,因此,每当提出问题时,我都需要一个基于时间的进度条,该进度条实际上会减少。时间会很短,比如 1-3 秒。我需要一个解决方案,以便我可以制作一个根据时间动画为零的进度条。

感谢您的回复。

【问题讨论】:

    标签: windows-phone-8 progress-bar


    【解决方案1】:

    您可以针对 ProgressBar 的 Value 属性创建动画。
    假设您已将 ProgressBar 添加为:

    <ProgressBar x:Name="progress"/>
    

    然后将页面资源中的故事板添加为(根据您的要求设置持续时间):

    <phone:PhoneApplicationPage.Resources>
        <Storyboard x:Name="sb">
            <DoubleAnimation Storyboard.TargetName="progress"
                                     Storyboard.TargetProperty="Value"
                                     From="100" To="0" Duration="0:0:3"/>
        </Storyboard>
    </phone:PhoneApplicationPage.Resources>
    

    从后面的代码运行动画:

    sb.Begin();
    

    【讨论】:

      【解决方案2】:

      创建此测试应用程序,然后将其用作参考来创建您自己的应用程序或根据需要对其进行自定义。将以下 XAML 添加为您的页面 ContentPanel

      <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
          <StackPanel>
              <ProgressBar Name="progBar" Margin="0,24,0,0" />
              <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Time (s) : " Margin="12,24,0,0"/>
                  <TextBox Name="txtTime" Width="100" InputScope="Number" />
              </StackPanel>
              <Button Content="Start" HorizontalAlignment="Stretch" VerticalAlignment="Top" Click="Button_Click" />
          </StackPanel>
      </Grid>
      

      然后将下面的代码添加到后面的C​​#代码中。先声明DispatecherTimer

      DispatcherTimer timer;
      

      然后添加此代码..

      private void Button_Click(object sender, RoutedEventArgs e)
      {
          StartCountDown(int.Parse(txtTime.Text));
      }
      
      private void StartCountDown(int secs)
      {
          timer = new DispatcherTimer();
          timer.Interval = TimeSpan.FromSeconds(0.1);
      
          progBar.Maximum = secs;
          progBar.Value = secs;
          timer.Tick += timer_Tick;
          timer.Start();
      }
      
      void timer_Tick(object sender, EventArgs e)
      {
          progBar.Value = progBar.Value - 0.1;
          if (progBar.Value == 0)
          {
              timer.Stop();
              timer.Tick -= timer_Tick;
              MessageBox.Show("Time Over");
          }
      }
      

      运行应用程序,输入一个以秒为单位的值,然后查看ProgressBar 倒计时。希望这会有所帮助。

      【讨论】:

        【解决方案3】:

        【讨论】:

        • 您能否在回答中包含您提供的链接中的关键信息?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多