I have a TextBlock control to which I would like to bind current System Date , how can I do that by Code Behind ?
The goal is to display in this TecBlock the current System Date and Time and I do not need the control refresh all the time ,only once.
I hope that is most simple Code.I don't want to Create dateTime Property. follow is my code:it is Wrong that it can't find BindSource
Binding bd = new Binding("System.DateTime.Now");
bd.Source = this;
textBox.SetBinding(TextBox.TextProperty, bd);
Thanks for help
This will show the Current date only once .
create a namespace alias:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
<TextBlock Text="{Binding Source={x:Static sys:DateTime.Today},
StringFormat='{}{0:dddd, MMMM dd, yyyy}'}"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With