DatePicker.SelectedDate not changing when Text is input

前端 未结 5 760
无人共我
无人共我 2020-12-16 14:23

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 t

5条回答
  •  青春惊慌失措
    2020-12-16 15:16

    This is probably a bit late, but I've been stuck on this for a while now.

    If you have another WPF element you can change focus to that at the beginning of your button press event, this will make the datepicker process any text entered in it's textbox. I've only tried this with a combobox but it seems to work and it allows you to still have custom formatting on your dates (ie 26/04/2016 rather than 04/26/2016). I assume you would be able to use an invisible element as well if you don't have anything to change focus to.

        private void btnInbound_Complete_Click(object sender, RoutedEventArgs e)
        {
            if (Validation())
            {
                comboInbound_Result.Focus();//THIS IS SO THAT ANY MANUAL DATEPICKER ENTRY IS ACCEPTED BEFORE THE REST OF THE BUTTON CODE IS RUN
                SQLinbound_CompleteItem();
                ClearAll();
            }
        }
    

提交回复
热议问题