I have found a way to fix the RadTimePicker using WPF styling and event setters. First off, add a ResourceDictionary (ControlStyles.xaml):
<ResourceDictionary x:Class="EventSetterWPF.ControlStyles"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tc="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input">
<Style TargetType="{x:Type tc:RadTimePicker}">
<EventSetter Event="ParseDateTimeValue" Handler="RadTimePicker_ParseDateTimeValue" />
</Style>
</ResourceDictionary>
Next off, add a codebehind for the ResourceDictionary (ControlStyles.xaml.cs)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Telerik.Windows.Controls;
namespace EventSetterWPF
{
public partial class ControlStyles : ResourceDictionary
{
public ControlStyles()
{
InitializeComponent();
}
public void RadTimePicker_ParseDateTimeValue(object sender, ParseDateTimeEventArgs e)
{
if (e.IsParsingSuccessful)
{
string originalString = e.TextToParse.Replace(":", "");
if (!string.IsNullOrEmpty(originalString) && originalString.Length == 4 && originalString.StartsWith("0"))
{
int enteredHour = -1;
int enteredMinutes = -1;
if (int.TryParse(originalString.Substring(0, 2), out enteredHour) &&
(int.TryParse(originalString.Substring(2, 2), out enteredMinutes)) &&
e.Result.HasValue)
{
DateTime originalValue = e.Result.Value;
DateTime? newValue = new DateTime(originalValue.Year, originalValue.Month, originalValue.Day,
enteredHour, enteredMinutes, 0);
e.Result = newValue;
}
}
}
}
}
}
Add the resource dictionary to App.xaml:
<Application x:Class="EventSetterWPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="TestRadTimePicker.xaml">
<Application.Resources>
<ResourceDictionary Source="ControlStyles.xaml" />
</Application.Resources>
</Application>
Now, all your RadTimePicker will have this custom datetime parsing. Similar strategy can be used for RadDatePicker and RadDateTimePicker. I had to fix these issues at work today for multiple Telerik Controls.
For example, typing "0130" did not parse to 01:30 AM, rather it resulted in 13:00 (PM) being set. Using the strategy above made the parsing of the RadTimePicker work again.
I included a blog article for the interested reader here:
http://toreaurstad.blogspot.com/2012/03/styling-user-controls-in-wpf-with.html