Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

wpf - DatePicker.SelectedDate not changing when Text is input

When my users select a date via the Calander control within the DatePicker, the value gets correctly bound to the underlying object. BUT, if the user types the date within the DatePicker, then clicks a button, the text is not set to the SelectedDate property.

The user has to remove the cursor from the TextBox within the DatePicker for the bound object to be updated.

 <toolkit:DatePicker Name="_dpField" Grid.Column="1" MinWidth="100"
               ToolTip="{Binding Path=ToolTipText}"
               TextInput="_dpField_TextInput"
               SelectedDate="{Binding Path=Value, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>

HELP! how do i make sure that this typed value is used within the buttons event code?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found a easier solution where I don't need the DateConverter.

I only bound to the Text Property and use TargetNullValue=''.

<DatePicker x:Name = "dpDisbursementDate" 
            Text = "{Binding NameOfMyProperty, Mode=TwoWay,    
            UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, 
            TargetNullValue=''}"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...