I am writing a simple code in UWP where the user can select date from CalendarDatePicker and the app will show the selected date in a TextBlock and do some functionalities. How can I do that?
I have tried to do it with ToString() method. It shows full form of the date (ex: 1/1/2019 10:27 AM +06:00)
But I want to show the date and the month only.
Here is the code that I've written:
XAML
<CalendarDatePicker Name="calDatePicker"
DateChanged="calDatePicker_DateChanged"
Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="5,0,0,1"/>
<TextBlock Name="dateText"
Style="{StaticResource sampleText}"
Text="Preferred Time"/>
C#:
private void calDatePicker_DateChanged(CalendarDatePicker sender, CalendarDatePickerDateChangedEventArgs args)
{
if (calDatePicker.Date < DateTime.Now)
{
dateText.Text = "Order must be placed between this day and next 5 days.";
}
else
{
dateText.Text = calDatePicker.Date.ToString();
counter = true;
}
}