I'm working in a WP 8.1 application (non SL) and have the following XAML code:
<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).
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.
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!
Thanks Jon.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.