Click or drag to resize

DateTimeSource Class

Provides values for date and time suitable for bindings.
Inheritance Hierarchy
SystemObject
  TomsToolbox.WpfDateTimeSource

Namespace:  TomsToolbox.Wpf
Assembly:  TomsToolbox.Wpf (in TomsToolbox.Wpf.dll)
Syntax
public class DateTimeSource : INotifyPropertyChanged

The DateTimeSource type exposes the following members.

Constructors
  NameDescription
Public methodDateTimeSource
Initializes a new instance of the DateTimeSource class.
Top
Properties
  NameDescription
Public propertyNow
Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.
Public propertyToday
Gets the current date.
Public propertyUpdateInterval
Gets or sets the interval in which the PropertyChanged event is raised for all properties.
Public propertyUtcNow
Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).
Top
Methods
Events
  NameDescription
Public eventPropertyChanged
Occurs when a property value changes.
Top
Fields
  NameDescription
Public fieldStatic memberDefault
The default singleton object. Use this as a source for binding that supports manual updating.
Top
Extension Methods
Remarks
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:

XAML
<FrameworkElement.Resources>
  <toms:DateTimeSource x:Key="TimeSource" UpdateInterval="00:00:01" />
</FrameworkElement.Resources>
...
<TextBox Text=Binding Path=Now, Source=StaticResource TimeSource}}&quot; /&gt;
See Also