public
class
CustomDialogViewModel : DependencyObject
{
public
static
readonly
DependencyProperty DurationProperty =
DependencyProperty.Register(
"Duration"
,
typeof
(TimeSpan),
typeof
(CustomDialogViewModel),
null
);
public
static
readonly
DependencyProperty StartProperty =
DependencyProperty.Register(
"Start"
,
typeof
(DateTime),
typeof
(CustomDialogViewModel),
new
PropertyMetadata(OnStartEndChanged));
public
static
readonly
DependencyProperty EndProperty =
DependencyProperty.Register(
"End"
,
typeof
(DateTime),
typeof
(CustomDialogViewModel),
new
PropertyMetadata(OnStartEndChanged));
public
TimeSpan Duration
{
get
{
return
(TimeSpan)GetValue(DurationProperty); }
set
{ SetValue(DurationProperty, value); }
}
public
DateTime Start
{
get
{
return
(DateTime)GetValue(StartProperty); }
set
{ SetValue(StartProperty, value); }
}
public
DateTime End
{
get
{
return
(DateTime)GetValue(EndProperty); }
set
{ SetValue(EndProperty, value); }
}
private
static
void
OnStartEndChanged(DependencyObject s, DependencyPropertyChangedEventArgs e)
{
var dvm = s
as
CustomDialogViewModel;
dvm.Duration = dvm.End - dvm.Start;
}
}