Hi There,
I simply bind the SelectedTime to a TimeSpan? property in the ViewModel. The problem I am having is that when the TimeSpan? is set to null, the TimePicker control still displays the previous non null value.
To get the behavior to work, first click 'Set Time Picker to 5am' then 'Set Time Picker To Null'.
I am using 'Telerik.Windows.Controls.Input' version '2010.2.714.1040'
Please advice if this is the correct way to bind to the TimePicker?
ViewModel
XAML
thanks
Sam
I simply bind the SelectedTime to a TimeSpan? property in the ViewModel. The problem I am having is that when the TimeSpan? is set to null, the TimePicker control still displays the previous non null value.
To get the behavior to work, first click 'Set Time Picker to 5am' then 'Set Time Picker To Null'.
I am using 'Telerik.Windows.Controls.Input' version '2010.2.714.1040'
Please advice if this is the correct way to bind to the TimePicker?
ViewModel
public
class
MainPageViewModel : INotifyPropertyChanged {
private
TimeSpan? _selectedTime;
public
MainPageViewModel() {
SetTimePickerCommand =
new
DelegateCommand(( o ) => {
SelectedTime =
new
TimeSpan(5, 0, 0);
}, ( o ) => {
return
true
;
});
SetTimePickerToNullCommand =
new
DelegateCommand(( o ) => {
SelectedTime =
null
;
}, ( o ) => {
return
true
;
});
}
public
ICommand SetTimePickerToNullCommand {
get
;
private
set
; }
public
ICommand SetTimePickerCommand {
get
;
private
set
; }
public
TimeSpan? SelectedTime {
get
{
return
_selectedTime; }
set
{
if
(_selectedTime == value) {
return
;
}
_selectedTime = value;
OnPropertyChanged(
"SelectedTime"
);
}
}
#region INotifyPropertyChanged Members
public
event
PropertyChangedEventHandler PropertyChanged;
private
void
OnPropertyChanged(
string
propertyName ) {
if
(PropertyChanged ==
null
) {
return
;
}
PropertyChanged(
this
,
new
PropertyChangedEventArgs(propertyName));
}
#endregion
}
XAML
<
UserControl.Resources
>
<
local:MainPageViewModel
x:Key
=
"ViewModel"
/>
</
UserControl.Resources
>
<
UserControl.DataContext
>
<
Binding
Source
=
"{StaticResource ViewModel}"
/>
</
UserControl.DataContext
>
<
StackPanel
>
<
telerikInput:RadTimePicker
Grid.Row
=
"0"
Grid.Column
=
"0"
SelectedTime
=
"{Binding SelectedTime}"
/>
<
Button
Command
=
"{Binding SetTimePickerToNullCommand}"
Content
=
"Set Time Picker To Null"
/>
<
Button
Command
=
"{Binding SetTimePickerCommand}"
Content
=
"Set Time Picker To 5 AM"
/>
</
StackPanel
>
thanks
Sam