This is a migrated thread and some comments may be shown as answers.

DataBinding to SelectedTime

1 Answer 101 Views
TimePicker
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 27 Jul 2010, 10:34 AM
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

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

1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 29 Jul 2010, 04:41 PM
Hello Sam,

Thank you for contacting us.

Thank you for reporting this bug, it helps us in improving our products. I am glad to give you points for reporting this abnormal behavior of our RadTimePicker control. We will fix this bug in one of our future releases. You can track this progress in our Public Issue Tracking System (PITS) with Issue ID = 2902.

Please do not hesitate to contact us if you require any further information.

Best wishes,
George
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TimePicker
Asked by
Sam
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or