| DateTimeSource Class |
Provides values for date and time suitable for bindings.
Inheritance Hierarchy Namespace: TomsToolbox.WpfAssembly: TomsToolbox.Wpf (in TomsToolbox.Wpf.dll) Version: 2.21.0+44d18b541fc9419ec3c549350a832394661b2a4d
XMLNS for XAML: Not mapped to an xmlns.
Syntax public class DateTimeSource : INotifyPropertyChanged
Public Class DateTimeSource
Implements INotifyPropertyChanged
The DateTimeSource type exposes the following members.
Constructors | Name | Description |
---|
| DateTimeSource |
Initializes a new instance of the DateTimeSource class.
|
TopProperties | Name | Description |
---|
| Now |
Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.
|
| Today |
Gets the current date.
|
| UpdateInterval |
Gets or sets the interval in which the PropertyChanged event is raised for all properties.
|
| UtcNow |
Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).
|
TopMethods Events Fields | Name | Description |
---|
| Default |
The default singleton object. Use this as a source for binding that supports manual updating.
|
TopExtension Methods | Name | Description |
---|
| SafeCastT |
Performs a cast from object to T, avoiding possible null violations if T is a value type.
(Defined by ObjectExtensions) |
TopRemarks
This expression in XAML would be static, since the Source is never updated and would always have
it's initial value,
UpdateTarget won't have any effect.
MyDayOfWeek="{Binding Path=DayOfWeek, Source={x:Static system:DateTime.Today}}"
Using
DateTimeSource instead,
UpdateTarget will work,
and MyDayOfWeek will be updated with the actual value:
MyDayOfWeek="{Binding Path=Today.DayOfWeek, Source={x:Static toms:DateTimeSource.Default}}"
Another usage is to use a local instance with timer triggered property change events:
<FrameworkElement.Resources>
<toms:DateTimeSource x:Key="TimeSource" UpdateInterval="00:00:01" />
</FrameworkElement.Resources>
...
<TextBox Text=Binding Path=Now, Source=StaticResource TimeSource}}" />
See Also