在标签/文本块中显示并刷新当前日期和时间
答
是的,这是可能的!我的解决方案(在自定义WPF组件中)非常类似于this solution,仅与DependencyProperty,XAML中的绑定和时间/日期格式相关。
CS:
//...
void timer_Tick(object sender, EventArgs e)
{
Time = DateTime.Now;
}
public DateTime Time
{
get { return (DateTime)GetValue(TimeProperty); }
set { SetValue(TimeProperty, value); }
}
public static readonly DependencyProperty TimeProperty = DependencyProperty.Register(nameof(Time), typeof(DateTime), typeof(ChannelOverview), new PropertyMetadata(DateTime.Now));
XAML:
<TextBox Text="{Binding Time, StringFormat='{}{0:HH:mm}'}"/>
是的,这是可能的。但你到目前为止尝试过什么? – Zabavsky
参考这[链接](http://stackoverflow.com/questions/9490333/updating-a-datetime-to-a-label-in-wpf)..这就是你要找的可能 – Glk
**是** ,这是可能的:P – atiyar