Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Commented Issue: Masked DateTimePicker [22326]

$
0
0
I changed the DateTimePicker template using MaskedTextBox and it does not work properly. The position of the caret is changed when I try to enter a date.
How can I fix this?
Comments: ** Comment from web user: BoucherS **

Hi,

For the selection in the calendar not being displayed in the MaskedTextBox, here's what I think is happening.

You use "."(period) in the MaskedTextBox.Mask and your current Culture is, let's say, "fr-CA". In that culture, "."(periods) are converted as ","(comma). So at the end, the MaskedTextBox will use ","(comma).
You use "."(period) in your DateTimePicker.Format, so your Calendar SelectedValue contains "."(periods).
When it's time to validate this selection in the MaskedTextBox, the current culture is used by the MaskedTextBox. Since ","(comma) is not "."(period), the validation of the selected value by the MaskedTextBox fails : No dates selected.

Make sure your DateTimePicker FormatString matches your current Culture since the inner MaskedTextBox will use the current Culture. For a Culture "fr-CA", your DatetimePicker FormatString would use ","(comma), not "."(period) :
```
<xctk:DateTimePicker FormatString="dd,MM,yyyy HH:mm:ss" />
```
Another options would be to modify the Culture of your Window :
```
public MainWindow()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo( "en-US" );
Thread.CurrentThread.CurrentUICulture = new CultureInfo( "en-US" );
InitializeComponent();
}
```
and keep using "."(period) in your MaskedTextBox and DateTimePicker :
```
<xctk:DateTimePicker FormatString="dd.MM.yyyy HH:mm:ss" />

<xctk:MaskedTextBox x:Name="PART_TextBox" Mask="00.00.0000 00:00:00"/>
```


Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>