Hi
I'm trying to override the OnPreviewKeyDown event attached the to DateTimeEdit control so i can handle alpha shortcut keys.
I've been trying to do this using a controltemplate with the following code defined in a class without much luck.
public class DTPicker : DateTimeEdit
{
public DTPicker()
{
this.DefaultStyleKey = typeof(DTPicker);
}
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
DateTime workingDt = (this.DateTime == null ? System.DateTime.Today : (DateTime)this.DateTime);
if (e.Key == Key.Delete)
{
this.DateTime = null;
e.Handled = true;
}
else if (e.Key == Key.T)
{
this.DateTime = System.DateTime.Today;
e.Handled = true;
}
else if (e.Key == Key.OemPlus || e.Key == Key.Add)
this.DateTime = workingDt.AddDays(1);
else if (e.Key == Key.OemMinus || e.Key == Key.Subtract)
this.DateTime = workingDt.AddDays(-1);
}
else
base.OnPreviewKeyDown(e);
}
}
and using a style defined in the global resource dictionary pointing to the class containing the above code
<Style TargetType="sf:DateTimeEdit">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ct:DTPicker}" />
</Setter.Value>
</Setter>
</Style>
Unfortunately receiving a template error with this so hoping you could advise what I need to change to get this working.
Thanks
Allan