0
是否可以在WPF標籤/文本塊中顯示和刷新當前日期和時間? 也許一些示例代碼?在標籤/文本塊中顯示並刷新當前日期和時間
是否可以在WPF標籤/文本塊中顯示和刷新當前日期和時間? 也許一些示例代碼?在標籤/文本塊中顯示並刷新當前日期和時間
是的,這是可能的!我的解決方案(在自定義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