WPF Datepicker Text property not updating the view model

0 votes
asked Jul 4, 2013 in WPF by anonymous

I am using Wpf 4.0 Datepicker control in my application and I bound the text property of that datepicker to a Datetime type property of the view model. I have implemented the INotifyPropertyChanged interface in my view model, also I have used UpdateSourceTrigger and set to LostFocus. Still, the view model property is not reflecting the changes from datepicker text property. What would be the reson?

<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Vertical">
 <DatePicker Text="{Binding Path=Request.StartDate, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Width="100" VerticalAlignment="Center" Margin="0,5,0,5" />
 <DatePicker Text="{Binding Path=Request.EndDate, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Width="100" VerticalAlignment="Center" Margin="0,5,0,5" />
</StackPanel>
Share

1 Answer

+1 vote
answered Jul 4, 2013 by Aadhira (1,213 points)
selected Jul 4, 2013 by administrator
 
Best answer

I think the Text property of the Datepicker will not update the view model property. You can try this by changing the view model property binding from Text property to SelectedDate property like below.

<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Vertical">
 <DatePicker SelectedDate="{Binding Path=Request.StartDate, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Width="100" VerticalAlignment="Center" Margin="0,5,0,5" />
 <DatePicker SelectedDate="{Binding Path=Request.EndDate, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Width="100" VerticalAlignment="Center" Margin="0,5,0,5" />
</StackPanel>

Your answer

Preview

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
site design / logo / content © 2013 - 2015 pinfaq.com
...