CalendarView represents a control that enables a user to select a date by using a visual calendar display.
Step 1. Open a blank app and add CalendarView and Textblock control either from the toolbox or by copying the following XAML code into your grid.
- <TextBlock Text="Calender View" FontSize="20"></TextBlock>
- <StackPanel Margin="0,15,0,0">
- <CalendarView Name="myCalender" Margin="20,20,0,0" SelectedDatesChanged="myCalender_SelectedDatesChanged" SelectionMode="Multiple" />
- <TextBlock Name="datesSelected" Foreground="Green" Margin="0,10,0,0"></TextBlock>
- </StackPanel>
Selection Mode defines whether to select single or multiple dates.
Step 2: Copy and paste the following code to the myCalender_SelectedDatesChanged event in the cs page.
- var selectedDates = sender.SelectedDates.Select(p => p.Day.ToString() + "/" + p.Month.ToString()).ToArray();
- var multipleDates = string.Join(", ", selectedDates);
- datesSelected.Text = "The selected dayes are " + multipleDates;
Step 3: Run your application and select a date. The selected dates will be shown in our TextBlock assigned.