简体   繁体   English

将DispatcherTimer绑定到进度栏XAML WP 8.1

[英]Bind DispatcherTimer to Progress Bar XAML WP 8.1

I'm working in a WP 8.1 application (non SL) and have the following XAML code: 我正在WP 8.1应用程序(非SL)中工作,并具有以下XAML代码:

<Page>
    <Grid>
        <ProgressBar x:Name="TimeBar" IsIndeterminate="False" Maximum="200" Value="30" Height="10" Width="300"/>
    </Grid>
</Page>

This gives me the following: 这给了我以下内容:

进度条

I want to bind a timer object, so that as the time ticks and goes forward, the progress bar moves with it, until the timer stops (reaches 1 minute). 我想绑定一个计时器对象,以便随着时间的推移而前进,进度条将随之移动,直到计时器停止(到达1分钟)。

I have the following code, but it doesn't seem to work. 我有以下代码,但它似乎不起作用。

namespace BarWithTimer
{
    public sealed partial class MainPage : Page
    {
        public DispatcherTimer Timer;

        public MainPage()
        {
            InitializeComponent();
            Timer = new DispatcherTimer();
            Timer.Tick += TimerOnTick;
            Timer.Interval = new TimeSpan(0, 1, 0);
            Timer.Start();
            NavigationCacheMode = NavigationCacheMode.Required;
        }

        private void TimerOnTick(object sender, object o)
        {
            TimeBar.Value += 10;
        }
    }
}

As suggested by Jon, all I had to do was fix the interval on the timer. 正如乔恩(Jon)所建议的那样,我要做的就是固定计时器的间隔。

Timer.Interval = new TimeSpan(0, 0, 0, 0, 50);

This now calls the Tick handler every 50 milliseconds, and I can see my progress bar moving! 现在,它每隔50毫秒调用一次Tick处理程序,我可以看到进度条移动了!

Thanks Jon. 谢谢乔恩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM