Sliverlight中怎么获取动态当前时间

qq_34466942 2016-03-29 12:41:02
我是简单的获取了一下当前时间
this.lblDate.Content = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
如何能让他动起来呢
...全文
87 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
五毒狼烟 2016-03-29
  • 打赏
  • 举报
回复
http://blog.csdn.net/woshihaorenyajun/article/details/51005198
q107770540 2016-03-29
  • 打赏
  • 举报
回复
在XAML中:
<StackPanel Width="205"
                    Margin="0,0,57,0"
                    HorizontalAlignment="Right">
            <TextBlock Height="Auto"
                       Margin="10,5,0,0"
                       Name="tbDateText"
                       Foreground="White"
                       FontWeight="Bold"
                       FontFamily="Arial"
                       FontSize="15" />
            <TextBlock Height="Auto"
                       Margin="10,5,0,0"
                       Name="tbTimeText"
                       Foreground="#ffa51f"
                       FontWeight="Bold"
                       FontFamily="Calibri"
                       FontSize="23" />
        </StackPanel>
在主窗体的cs中代码为:
/// <summary>  
/// 定义一个定时器
/// </summary>
 private DispatcherTimer ShowTimer;
 public MainWindow()  
{  
           InitializeComponent();
            ShowTime();    //在这里窗体加载的时候不执行文本框赋值,窗体上不会及时的把时间显示出来,而是等待了片刻才显示了出来
            ShowTimer = new System.Windows.Threading.DispatcherTimer();
            ShowTimer.Tick += new EventHandler(ShowCurTimer);//起个Timer一直获取当前时间
            ShowTimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
            ShowTimer.Start();     
 }     
public void ShowCurTimer(object sender, EventArgs e)
{      
       ShowTime();
 }
//ShowTime方法
private void ShowTime() 
{
            //获得年月日
            this.tbDateText.Text = DateTime.Now.ToString("yyyy/MM/dd");   //yyyy/MM/dd
            //获得时分秒
            this.tbTimeText.Text = DateTime.Now.ToString("HH:mm:ss");
}

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧