I've got a View with a DatePicker bound to a DateTime property in my ViewModel. However, the date value always appears as null, even when I select a different value than the default. Anyone have success with the DatePicker? If so, what am I getting wrong?
Relevant Code:
View:
<DatePicker x:Name="startDateUpdatePick" HorizontalAlignment="Left" Height="23" VerticalAlignment="Top" Width="120" Margin="1.5"
Text="{Binding SelectedProjectData.ProjectStartDate, UpdateSourceTrigger=PropertyChanged, TargetNullValue=''}"/>
ViewModel:
public PSViewModel()
{
SelectedProjectData = new Project();
}
Model:
public class Project : INotifyPropertyChanged
{
private DateTime _projectStartDate;
public DateTime ProjectStartDate
{
get { return _projectStartDate; }
set
{
_projectStartDate = value;
RaisePropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged([CallerMemberName] string caller = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(caller));
}
}
Edit: the XAML is bound to a non-nullable DateTime, but I have other datepickers in the same setup that are bound to nullable DateTime and they don't work either.