当前日期和时间WPF标签 [英] Current Date and Time WPF label

查看:92
本文介绍了当前日期和时间WPF标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的C#WPF应用程序中有一个名为DateTime的标签,我希望它显示当前日/月和时间HH:MM:SS



< pre lang =cs> private void DateTime_Loaded( object sender,RoutedEventArgs e)
{
DateTime.Content = DateTime.Now.ToShortDateString( DD / MM HH:MM:SS);
}





但我收到此错误

标签' 不包含现在'的定义 并且没有扩展方法'现在' 接受第一个可以找到类型'标签' 的参数(您是否缺少using指令或汇编引用?)  

解决方案

Quote:

我有一个名为DateTime的标签







这是一个非常奇怪的名称!你正在使用类DateTime的名称作为控件,你不明白吗?您需要重新命名您的标签(例如myDateTime)。


I have a label called DateTime in my C# WPF application and I want it to display the Current Day/Month and the time HH:MM:SS

private void DateTime_Loaded(object sender, RoutedEventArgs e)
{
    DateTime.Content = DateTime.Now.ToShortDateString("DD/MM HH:MM:SS");
}



but i get this error

Label' does not contain a definition for 'Now' and no extension method 'Now' accepting a first argument of type 'Label' could be found (are you missing a using directive or an assembly reference?)

解决方案

Quote:

I have a label called DateTime




It is a really strange name for a Label! You are using the name of class "DateTime" for a control, don't you see it? You need to re-name your Label (e.g. "myDateTime").


这篇关于当前日期和时间WPF标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆