I have requirement on select of Todays Date in RadDatePicker , it should return string "Today".
Same as For Tommorows date, should return string as Tommorow.
Is it possible such type of behaviour in Telerik.
Please do the needul.
4 Answers, 1 is accepted
You can use the CurrentDateTimeText to find the current selected date. The property is of the string type so you can return every possible string format. Follow the example bellow:
<
Window.Resources
>
<
local:DateConverter
x:Key
=
"converter"
/>
</
Window.Resources
>
<
Grid
>
<
telerik:RadDatePicker
x:Name
=
"radDateTimePicker"
HorizontalAlignment
=
"Center"
VerticalAlignment
=
"Center"
ParseDateTimeValue
=
"radDateTimePicker_ParseDateTimeValue"
/>
<
TextBlock
Text
=
"{Binding CurrentDateTimeText, ElementName=radDateTimePicker, Converter={StaticResource converter}}"
HorizontalAlignment
=
"Center"
VerticalAlignment
=
"Top"
/>
</
Grid
>
public
class
DateConverter : IValueConverter
{
public
object
Convert(
object
value, Type targetType,
object
parameter, CultureInfo culture)
{
if
(value ==
null
)
{
return
null
;
}
DateTime date;
if
(DateTime.TryParse(value.ToString(),
out
date))
{
if
(date.Date == DateTime.Today)
{
return
"Today"
;
}
else
if
(date.Date == DateTime.Today.AddDays(1))
{
return
"Tommorow"
;
}
}
return
null
;
}
public
object
ConvertBack(
object
value, Type targetType,
object
parameter, CultureInfo culture)
{
return
value;
}
}
Greetings,
Kaloyan
the Telerik team
Thanks Kaloyan for the Valuable Info.
I need here to return a string Today in RadDateTimePicker's input box, not needed to bind to textbox.
I implemented below logic for that but it returns Today as a String on every date select.
It should return a string a only For Todays and Tommorows date.
<telerik:RadDateTimePicker x:Name="radDateTimePicker" HorizontalAlignment="Center" VerticalAlignment="Center" ParseDateTimeValue="radDateTimePicker_ParseDateTimeValue" />
private vo
id radDateTimePicker_ParseDateTimeValue(object sender, Telerik.Windows.Controls.ParseDateTimeEventArgs args)
{
DateTime date = System.DateTime.Now;
if (date.Date == DateTime.Today)
{
radDateTimePicker.DateTimeText = "Today";
}
else if (date.Date == DateTime.Today.AddDays(1))
{
radDateTimePicker.DateTimeText = "Tommorow";
}
}
I have fixed the issue.
By Mistake , i took a System date .
Here is the code
private
void radDateTimePicker_ParseDateTimeValue(object sender, Telerik.Windows.Controls.ParseDateTimeEventArgs args)
{
DateTime date = radDateTimePicker.DisplayDate;
if (date.Date == DateTime.Today)
{
radDateTimePicker.DateTimeText =
"Today";
}
else if (date.Date == DateTime.Today.AddDays(1))
{
radDateTimePicker.DateTimeText =
"Tommorow";
}
}
This was my idea too. The key point here is to use the ParseDateTimeValue event.
Best wishes,
Kaloyan
the Telerik team