文本块中的文本动态更改
Text in Textblock to change Dynamically
HubSection Tag="2" Name="Stopwatch" x:Uid="Stopwatch" Header="STOPWATCH"
DataContext="{Binding Groups[1]}" HeaderTemplate="{ThemeResource HubSectionHeaderTemplate}">
<DataTemplate>
<Grid>
<TextBox HorizontalAlignment="Center" Margin="10,36,11,350" TextWrapping="Wrap" Text="00:00:00"
VerticalAlignment="Center" IsReadOnly="True" Width="320" Height="63" BorderThickness="0"
Foreground="White" Background="Black" TextAlignment="Center" FontSize="42" CharacterSpacing="80"
FontFamily="Segoe WP Semibold" Loaded="TextBox_Loaded"/>
</Grid>
</DataTemplate>
</HubSection>
这是XAML部分
stopwatch_timer.Interval = new TimeSpan(0, 0, 0, 1, 0);
stopwatch_timer.Tick += Stopwatch_Tick;
TimerDisplay.Text = Start_Count++.ToString();
我的问题是如何增加文本块的零?
因为当我运行这个时,所有的零都消失了,它从一个零开始递增。
如果我对你的问题理解正确,这可能会对你有所帮助:
private TimeSpan time;
private void Timer()
{
DispatcherTimer stopwatch_timer = new DispatcherTimer();
stopwatch_timer.Interval = new TimeSpan(0, 0, 0, 1, 0);
stopwatch_timer.Tick += new EventHandler(stopwatch_timer_Tick);
stopwatch_timer.Start();
time = stopwatch_timer.Interval;
}
void stopwatch_timer_Tick(object sender, EventArgs e)
{
TimerDisplay.Text = time.ToString();
time = time.Add(((DispatcherTimer)sender).Interval);
}
您需要创建一个 Timer tick 事件处理程序来显示时间。
// creating timer instance
DispatcherTimer newTimer = new DispatcherTimer();
// timer interval specified as 1 second
newTimer.Interval = TimeSpan.FromSeconds(1);
// Sub-routine OnTimerTick will be called at every 1 second
newTimer.Tick += OnTimerTick;
// starting the timer
newTimer.Start();
这是 OnTimerTick
的代码
void OnTimerTick(Object sender, EventArgs args)
{
// text box property is set to current system date.
// ToString() converts the datetime value into text
TimerDisplay.Text = DateTime.Now.ToString();
}
完成这个 link http://developer.nokia.com/community/wiki/Implement_timers_in_Windows_Phone
HubSection Tag="2" Name="Stopwatch" x:Uid="Stopwatch" Header="STOPWATCH"
DataContext="{Binding Groups[1]}" HeaderTemplate="{ThemeResource HubSectionHeaderTemplate}">
<DataTemplate>
<Grid>
<TextBox HorizontalAlignment="Center" Margin="10,36,11,350" TextWrapping="Wrap" Text="00:00:00"
VerticalAlignment="Center" IsReadOnly="True" Width="320" Height="63" BorderThickness="0"
Foreground="White" Background="Black" TextAlignment="Center" FontSize="42" CharacterSpacing="80"
FontFamily="Segoe WP Semibold" Loaded="TextBox_Loaded"/>
</Grid>
</DataTemplate>
</HubSection>
这是XAML部分
stopwatch_timer.Interval = new TimeSpan(0, 0, 0, 1, 0);
stopwatch_timer.Tick += Stopwatch_Tick;
TimerDisplay.Text = Start_Count++.ToString();
我的问题是如何增加文本块的零?
因为当我运行这个时,所有的零都消失了,它从一个零开始递增。
如果我对你的问题理解正确,这可能会对你有所帮助:
private TimeSpan time;
private void Timer()
{
DispatcherTimer stopwatch_timer = new DispatcherTimer();
stopwatch_timer.Interval = new TimeSpan(0, 0, 0, 1, 0);
stopwatch_timer.Tick += new EventHandler(stopwatch_timer_Tick);
stopwatch_timer.Start();
time = stopwatch_timer.Interval;
}
void stopwatch_timer_Tick(object sender, EventArgs e)
{
TimerDisplay.Text = time.ToString();
time = time.Add(((DispatcherTimer)sender).Interval);
}
您需要创建一个 Timer tick 事件处理程序来显示时间。
// creating timer instance
DispatcherTimer newTimer = new DispatcherTimer();
// timer interval specified as 1 second
newTimer.Interval = TimeSpan.FromSeconds(1);
// Sub-routine OnTimerTick will be called at every 1 second
newTimer.Tick += OnTimerTick;
// starting the timer
newTimer.Start();
这是 OnTimerTick
void OnTimerTick(Object sender, EventArgs args)
{
// text box property is set to current system date.
// ToString() converts the datetime value into text
TimerDisplay.Text = DateTime.Now.ToString();
}
完成这个 link http://developer.nokia.com/community/wiki/Implement_timers_in_Windows_Phone