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