• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

夏乐

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

WPF中自动定时刷新

wpf第一次用,为了定时刷新这个页面,也是费了我老大的功夫了,皇天不负有心人,最终还是给它弄出来了,话不多说,直接上代码。

//定时器 private System.Timers.Timer timerNotice = null;

//定时刷新页面

private void TimeRefresh_SelectionChanged(object sender, SelectionChangedEventArgs e)

{

   double countTime = 0; string timeStr = this.TimeRefreshRCB.SelectionBoxItem.ToString();

  if ("关闭自动刷新".Equals(timeStr))

  {

  if (timerNotice != null) { timerNotice.Stop();

  picTour.time.Visibility = Visibility.Hidden;

  }

}

if ("开启".Equals(timeStr))

{

  if (timerNotice != null)

  {

  timerNotice.Stop();

  }

  countTime = 60 * 60 * 1000;

  timerNotice = null;

  picTour.time.Visibility = Visibility.Visible;

}

if(!"关闭自动刷新".Equals(timeStr) && timerNotice == null)

{

  QueryData();

  timerNotice = new System.Timers.Timer();

  picTour.PicDate2.DateTimeText = staticVar.showTime.ToString();

  timerNotice.Elapsed += new System.Timers.ElapsedEventHandler((o, eea) =>

   {

   QueryData();

  });

  timerNotice.Interval = countTime; timerNotice.Start();

  }

}
其实代码写出来不难,想的过程比较复杂,QueryData()是执行查询页面数据的方法,需要强调的是这里QueryData()必须是静态方法,TimeRefresh_SelectionChanged()是一个RadComboBox选择下拉框,你可以选择需要定时刷新的间隔。

posted on 2019-06-08 09:20  夏乐  阅读(2101)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3