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

RadDatePicker and UpdateSourceTrigger

5 Answers 846 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Rameshkumar Gundalapudi Vijayakumar
Top achievements
Rank 1
Rameshkumar Gundalapudi Vijayakumar asked on 23 Apr 2010, 06:47 PM
Hi,

I have a RadDatePicker where i can type the date and also i select a date.

I have a save button which should become enabled the moment i change the date in date picker.

Problem is only when i change the date using datepicker, the save is getting triggered. If i type in a date, only when the datepicker is lost focus, save is getting enabled. I want the save to be enabled the moment i type in some text using keyboard in the datepicker text box.

I am using the following code and it is not working

SelectedDate

 

 

="{Binding Path=SampleDate,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"

Note: In WPF datepicker i have a "Text" property where the UpdateSourceTrigger works perfectly. Need a similar behavior in RadDatePicker also.

Also I am using MVVM model. So i need suggestions which does not require XAML.cs change. All i should do is within XAML.

I have pasted a sample code below. Just type in some valid date in WPF datepicker, button will be enabled. But the same button is not getting enabled if i type in a date in RadDatePicker. You might know better than me... I need the same behavior as like the WPF date picker. Please help

 

<Window x:Class="DatePickerTextBoxSample.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
        Title="MainWindow" Height="350" Width="525">  
    <Grid> 
          
        <Button Name="SampleButton" Content="Click Here" Height="20" Width="150" HorizontalAlignment="Left" VerticalAlignment="Bottom" IsEnabled="{Binding Path=IsDateChanged,Mode=TwoWay}" Click="SampleButton_Click" /> 
        <DatePicker Text="{Binding Path=WpfDatePickerDate,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Height="25" HorizontalAlignment="Left" Margin="118,218,0,0" Name="datePicker1" VerticalAlignment="Top" Width="115" /> 
        <telerik:RadDatePicker SelectedDate="{Binding Path=RadDatePickerDate,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Height="25" HorizontalAlignment="Left" Margin="250,218,0,0" Name="datePicker2" IsDropDownOpen="False" VerticalAlignment="Top" Width="115" /> 
          
    </Grid> 
</Window> 
 

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Windows;  
using System.Windows.Controls;  
using System.Windows.Data;  
using System.Windows.Documents;  
using System.Windows.Input;  
using System.Windows.Media;  
using System.Windows.Media.Imaging;  
using System.Windows.Navigation;  
using System.Windows.Shapes;  
using System.ComponentModel;  
 
namespace DatePickerTextBoxSample  
{  
    /// <summary> 
    /// Interaction logic for MainWindow.xaml  
    /// </summary> 
    public partial class MainWindow : Window, INotifyPropertyChanged  
    {  
        private DateTime radDatePickerDate;  
        private DateTime wpfDatePickerDate;  
 
        public DateTime WpfDatePickerDate  
        {  
            get { return wpfDatePickerDate; }  
            set   
            {   
                wpfDatePickerDate = value;  
                IsDateChanged = true;  
                NotifyPropertyChanged("WpfDatePickerDate");  
            }  
        }  
 
        private bool _isDateChanged;  
 
        public bool IsDateChanged  
        {  
            get { return _isDateChanged; }  
            set   
            {   
                _isDateChanged = value;  
                NotifyPropertyChanged("IsDateChanged");  
            }  
        }  
          
        public DateTime RadDatePickerDate   
        {  
            get  
            {  
                return radDatePickerDate;  
            }  
            set  
            {  
                wpfDatePickerDate = value;  
                IsDateChanged = true;  
                NotifyPropertyChanged("RadDatePickerDate");  
            }  
        }  
         
        public MainWindow()  
        {  
            InitializeComponent();  
            thisthis.DataContext = this;  
        }  
 
        #region INotifyPropertyChanged Members  
 
        public event PropertyChangedEventHandler PropertyChanged;  
 
        protected void NotifyPropertyChanged(String info)  
        {  
            if (PropertyChanged != null)  
            {  
                PropertyChanged(this, new PropertyChangedEventArgs(info));  
            }  
        }  
 
        #endregion  
 
        private void SampleButton_Click(object sender, RoutedEventArgs e)  
        {  
            SampleButton.IsEnabled = false;  
        }  
    }  
}  
 

5 Answers, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 28 Apr 2010, 09:46 AM
Hello Rameshkumar Gundalapudi Vijayakumar,

The problem is that the typed value in the TextBox of the control is parsed to a valid date after loosing its focus. That means that the property will be updated after lost focus of the control. In your case you can use the KayUp event of the control to change the enabled condition of the button. Let us know if you need any further help.

Best wishes,
Kaloyan
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.
0
Rameshkumar Gundalapudi Vijayakumar
Top achievements
Rank 1
answered on 28 Apr 2010, 11:00 AM
I want some solution which doesn't use events in code behind. I need a solution which is MVVM friendly. Please let me know if there is any  such functionality with RadDatePicker.

Thanks,
Ramesh.
0
Kaloyan
Telerik team
answered on 29 Apr 2010, 02:44 PM
Hello Rameshkumar Gundalapudi Vijayakumar,

Please refer to this forum thread.

Regards,
Kaloyan
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.
0
Ras Ran
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 23 Jul 2020, 10:41 AM

 hii, i  want select  RadDatePicker first two digits (Month) on run time..could you please give possible method to solve this ??

Please check the attached picture.

Regards,

Ras Ran

 

 

0
Dilyan Traykov
Telerik team
answered on 27 Jul 2020, 01:50 PM

Hi Ras Ran,

You can select the first two digits from the RadDatePicker control by invoking the following method:

        private void RadButton_Click(object sender, RoutedEventArgs e)
        {
            var textBox = this.radDatePicker.ChildrenOfType<RadWatermarkTextBox>().First();
            textBox.Focus();
            Dispatcher.BeginInvoke(new Action(() => { textBox.Select(0, 2); }));
        }

I hope this works for you.

On a side note, as this query does not seem to be relevant to the original topic of this thread, may I kindly ask you to continue any further communication on the matter in a new forum thread or support ticket so that we keep our conversation history intact? Thank you in advance for your cooperation on the matter.

Regards,
Dilyan Traykov
Progress Telerik

Tags
DatePicker
Asked by
Rameshkumar Gundalapudi Vijayakumar
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Rameshkumar Gundalapudi Vijayakumar
Top achievements
Rank 1
Ras Ran
Top achievements
Rank 2
Iron
Veteran
Iron
Dilyan Traykov
Telerik team
Share this question
or