I have a silverlight date picker declared like below
<controls:DatePicker x:Name="DateFrom" Grid.Column="1" Grid.Row="0"></controls:DatePicker>
and a button declared as such.
<cc:NexButton x:Name="Submit" HorizontalAlignment="Right" Grid.Column="0" Content="Search" MouseLeftButtonUp="NexButton_MouseLeftButtonUp" ></cc:NexButton>
When I type a date in the date picker and press the search button without clicking out of the control It will go to the NexButton_MouseLeftButtonUp event.
When I try and get value out by going DateFrom.Text I get "" and when I try and access its selectedvalue by going DateFrom.SelectedDate I get today's date. Both of these cases are wrong and I should be getting the date entered. I thought it might of been a date validation error so I have tried different date formats such as US and UK date formats.
Why can I not access the date entered when I do not click/ tab out of the control? Is some event failing to fire.
Related
I allow a user to pick a date inside a DataGrid datepicker like
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<DatePicker SelectedDate="{x:Static System:DateTime.Now}"></ DatePicker>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
So if a user picks
03/04/2014 - fine, the date will go into the database as 2014-03-04 00:00:00.000
However there is an issue with the format and in the US style, I think, as if a user chooses
13/04/2014
The DatePicker will come up with an error - a red box will appear (this is not due to my vaildation) And the user will not be able to save to the database.
I know its because the month is first, the day is second and the year third (mm/dd/yyyy)
Is there a way I could use the datepicker in the UK format (dd/mm/yyyy) which should solve the problem?
Thanks
When I use the WPF 4.0 DatePicker with blackout date (or min/max), and the user enters a date that is blacked out by typing it in, the DatePicker reverts back to the original value.
This behavior is not the best for entering dates. If you key in the wrong year and tab out, it reverts back to the old value.
I'd like to be able to handle the error in code instead of just reverting back to the old value.
I'm using the Silverlight Toolkit DatePicker control.
If an user enters an invalid format date for example foo/bar/2001 then the DatePicker automatically 'ignores' the date and sets it back to the last date.
This behaviour is fine, except I'd like to actually show the date in error to the user (not corrected) and display some validation message etc so the user knows what the issue is
Does anyone have a snip or sample I can use that works in this way?
Any help greatly appreciated.
You could handle the DateValidationError event. Calendar control in Silverlight using C# has a bit of sample code showing how the event handler could be wired up.
I am creating a window that uses a WPF calendar to browse documents created on specified dates during the month shown. When the calendar changes month, I search a database for all documents created during that month, which I use to create a list of dates during the month that have documents.
In the Calendar control, I want to boldface those dates that have documents, in the same manner that Outlook boldfaces dates that have appointments.
So, here's my question: How do I boldface a specific date in the Calendar control's month view? Thanks for your help.
This may help.
http://www.c-sharpcorner.com/UploadFile/mahesh/539/Default.aspx
The "Selected Date and Selected Dates" area will show you how to select them, and further down it can show you how to format your calendar. That is, if you're using the same calendar which I hope you are. Hope this helps.
Selected Date and Selected Dates
SelectedDate property represents the current selected date. If multiple date selection is true, then SelectedDates property represents all selected dates in a Calendar. The following code snippet sets the SelectedDates in XAML at design-time.
<Calendar Name="MonthlyCalendar"
SelectionMode="MultipleRange"
DisplayDate="3/5/2010"
DisplayDateStart="3/1/2010"
DisplayDateEnd="3/31/2010"
FirstDayOfWeek="Tuesday"
IsTodayHighlighted="True"
xmlns:sys="clr-namespace:System;assembly=mscorlib" Margin="15,39,88,19">
<Calendar.SelectedDates>
<sys:DateTime>3/5/2010</sys:DateTime>
<sys:DateTime>3/15/2010</sys:DateTime>
<sys:DateTime>3/25/2010</sys:DateTime>
</Calendar.SelectedDates>
</Calendar>
The selected dates in a Calendar looks like Figure 8 where you can see March 5th, 15th, and 25th have a light blue background and represents the selected dates.
The following code snippet sets the SelectedDates property in WPF at run-time.
private void AddSelectedDates()
{
MonthlyCalendar.SelectedDates.Add(new DateTime(2010, 3, 5));
MonthlyCalendar.SelectedDates.Add(new DateTime(2010, 3, 15));
MonthlyCalendar.SelectedDates.Add(new DateTime(2010, 3, 25));
}
It turns out that boldfacing is hard-coded in several places, so I changed to date highlighting instead. I wrote a custom control that has a HighlightedDates list; adding a date to the list highlights the date and provides an optional tool tip for the date with whatever content the host app chooses.
I have written a CodeProject article titled Extending the WPF Calendar. The article includes the control and explains how I built it.
The default input behaviour of the DateTimePicker when entering a date is like this:
YYYY(Right Arrow)MM(Right Arrow)DD
The user want to enter the date like this:
YYYYMMDD
Is there any simple way of modifying the input behaviour of the DateTimePicker so that is does behave like the user want it to?
TIA
Expanding on PoweRoy's answer. Use a textbox and a datetimepicker. Make the datetimepicker small (just as big as the drop down arrow) and place it next to (or even inside) the textbox. Then you hook the dropdown and closeup events of the datetimepicker to get the value to and from the editbox.
I don't know how you use the DateTimePicker but what about using a simple editbox? (and validate date when a date is entered)
DateTimePicker is mostly used to choose a date without entering any number.