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

Datepicker databinding

1 Answer 350 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 26 Jan 2009, 11:24 AM
Hello!

Currently i am working on an application wich needs two datepickers - a StartDate and an EndDate . I am having problems binding this two controls with DateTime properties on an object . For binding values i am using the attribute SelectedDate = {Binding Path=StartDate}, but no binding is created . I would like to know if this is the correct way of binding this control to date fields or if there is another way of doing this... I have search throught the website/documentation but I can't find a proper response.

Any help would be great !
Thanks,
Ivan Frias.

1 Answer, 1 is accepted

Sort by
0
Miroslav Nedyalkov
Telerik team
answered on 27 Jan 2009, 10:24 AM
Hello Ivan,

What effect do you want to achieve? If you want one time binding this should be enough. If you want one way binding you should make your data object implement INotifyPropertyChanged interface and raise the PropertyChanged event when changing a property. If you want to create two way binding (if you want to make the DataPickers update the data object), you should mark the binding as TwoWay explicitly.
This is an example (the second DatePicker is two way bound):
        <StackPanel> 
            <Telerik:RadDatePicker Width="150" HorizontalAlignment="Center" 
                    VerticalAlignment="Center" IsTodayHighlighted="True" 
                    SelectedDate="{Binding Path=StartDate}" /> 
 
            <Telerik:RadDatePicker Width="150" HorizontalAlignment="Center" 
                    VerticalAlignment="Center" IsTodayHighlighted="True" 
                    SelectedDate="{Binding Path=EndDate, Mode=TwoWay}" /> 
        </StackPanel> 
And this is the class of the data object:
    public class Data : INotifyPropertyChanged 
    { 
        private DateTime startDate; 
 
        public DateTime StartDate 
        { 
            get 
            { 
                return this.startDate; 
            } 
            set 
            { 
                if (this.startDate != value) 
                { 
                    this.startDate = value; 
                    OnPropertyChanged("StartDate"); 
                } 
            } 
        } 
 
        private DateTime endDate; 
 
        public DateTime EndDate 
        { 
            get 
            { 
                return this.endDate; 
            } 
            set 
            { 
                if (this.endDate != value) 
                { 
                    this.endDate = value; 
                    OnPropertyChanged("EndDate"); 
                } 
            } 
        } 
 
        protected virtual void OnPropertyChanged(String propertyName) 
        { 
            if (System.String.IsNullOrEmpty(propertyName)) 
            { 
                return
            } 
            if (PropertyChanged != null
            { 
                PropertyChanged(thisnew PropertyChangedEventArgs(propertyName)); 
            } 
        } 
 
        public event PropertyChangedEventHandler PropertyChanged;         
    } 

Hope that helps.

All the best,
Miroslav Nedyalkov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
DatePicker
Asked by
Ivan
Top achievements
Rank 1
Answers by
Miroslav Nedyalkov
Telerik team
Share this question
or