Is it possible to show and refresh the current date and time in a WPF label/textblock? Maybe some sample code?
            Asked
            
        
        
            Active
            
        
            Viewed 2,423 times
        
    0
            
            
        - 
                    1Yes, it is possible. But what have you tried so far? – Zabavsky Aug 23 '12 at 12:44
- 
                    1Refer to this [link](http://stackoverflow.com/questions/9490333/updating-a-datetime-to-a-label-in-wpf) ..that's what you looking for probably – gunvant.k Aug 23 '12 at 12:58
1 Answers
0
            
            
        Yes, it is possible! My solution (in custom WPF component) is very similar like this solution only with DependencyProperty, binding and time/date formatting in 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}'}"/>
 
    
    
        honzakuzel1989
        
- 2,400
- 2
- 29
- 32
 
    