RadDatePicker and UpdateSourceTrigger

4 posts, 0 answers
  1. Rameshkumar Gundalapudi Vijayakumar
    Rameshkumar Gundalapudi Vijayakumar avatar
    6 posts
    Member since:
    Feb 2010

    Posted 23 Apr 2010 Link to this post

    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;  
            }  
        }  
    }  
     

  2. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 28 Apr 2010 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Rameshkumar Gundalapudi Vijayakumar
    Rameshkumar Gundalapudi Vijayakumar avatar
    6 posts
    Member since:
    Feb 2010

    Posted 28 Apr 2010 Link to this post

    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.
  5. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 29 Apr 2010 Link to this post

    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.
Back to Top