如何在WPF中使用计时器滴答事件

编程入门 行业动态 更新时间:2024-10-11 19:22:58
本文介绍了如何在WPF中使用计时器滴答事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用计时器滴答事件来更新使用此代码从Web服务绑定的文本框中的值.

i am using timer tick event to update values in textboxes binded from webservice using this code.

private void timer1_Tick(object sender, EventArgs e) { // timer.Interval = TimeSpan.FromSeconds(30); //activityGrid.DataContext = ActivityDataSet.Tables[0].DefaultView; var query = from data in ActivityDataSet.Tables[0].AsEnumerable() select new { ActivityType = data.Field<string>("ActLabel_Name"), ActivityName = data.Field<string>("ActivityName"), StartDate = data.Field<DateTime>("StartDt"), EndDate = data.Field<DateTime>("EndDt"), Instructor = data.Field<string>("InstName"), Location = data.Field<string>("Fac_Name"), Venue = data.Field<string>("Loc_Name") }; //activityGrid.DataContext = query.ToList(); int i = 1; while (i != 0) { i = i + 1; { //here spcalendar is staclpanel to which iam binding spCalendar.DataContext = query.ToList().ElementAt(i); break; } }

文本框仅一次更新,第二次不更新,问题是"i"的增量值没有更新,有人帮助了我.在这里,timesapn为1分钟.

textboxes are updating one time only ,second time they are not updating ,the problem is ''i''s incremented value is not getting updated someone help me out.here timesapn i gave as 1 minute.

推荐答案

原因如下: It''s because of this: int i = 1; while (i != 0) { i = i + 1; ...

您要告诉它在我不等于零时循环播放,并且根据您发布的代码,它绝不会等于零.最终,该代码将引发异常,因为i将索引超出列表的范围.

You''re telling it to loop while i is not equal to zero, and it''ds NEVER equal to zero based on the code you''ve posted. Eventually, ythat code will throw an exception because i will index beyond the bounds of the List.

更多推荐

如何在WPF中使用计时器滴答事件

本文发布于:2023-11-27 16:30:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638752.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计时器   事件   如何在   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!