
6 Answers, 1 is accepted
There is no Date type in the WPF framework. There is only DateTime that represents the Date and the Time value. If you want to get only the Date part of the DateTime value, you could use DateTime.ToShortDateString() method.
George
the Telerik team

<Window x:Class="BindingToNullableDateTime.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
Title="Window1" Height="300" Width="300">
<Grid Name="MainGrid" DataContext="{Binding}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<telerik:RadDateTimePicker Grid.Row="0"
InputMode="DatePicker"
Margin="5"
SelectedValue="{Binding MyNullableDateTime, Mode=TwoWay}" />
<TextBlock Grid.Row="1"
Margin="5"
Text="{Binding MyNullableDateTime}" />
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace BindingToNullableDateTime
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
void Notify(string propName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
private DateTime? myNullableDateTime;
public DateTime? MyNullableDateTime
{
get { return myNullableDateTime; }
set
{
myNullableDateTime = value;
Notify("MyNullableDateTime");
}
}
public Window1()
{
InitializeComponent();
MainGrid.DataContext = this;
}
}
}
I would suggest you to set a StringFormat to the binding:
<
TextBlock
Grid.Row
=
"1"
Margin
=
"5"
Text
=
"{Binding MyNullableDateTime, StringFormat=dd-MM-yyyy}"
/>
I hope this suits your needs.
George
the Telerik team

The TextBlock control is not the issue. The TextBlock control is simply so you can see what the MyNullableDateTime value is. The issue is that RadDateTimePicker sets the MyNullableDateTime value with date + time. When I save this value to the database I only want date + "12:00:00 AM". I am handling this with code in the setter, but I'm wondering if there is a way to do this with XAML.
Thanks,
Sam
I will paste my answer from the support ticket here as well:
This issue is fixed in our latest Q3 binaries. Could you please try our Q3 release and let me know if you still have any problems with RadControls. I will be glad to assist you further.
George
the Telerik team
