TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Calendar Control Tools In Windows Presentation Foundation
Guest User
Jan 31, 2017
6
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In this blog you will learn about Calendar Control Tools in Windows Presentation Foundation (WPF).
Introduction
This writing is about Calendar Control in Windows Presentation Foundation. Here I will be working with a demo of using Calendar in WPF on Visual Studio 2015.
Technical Requirements
Visual Studio 2015 installed on your PC.
About Calendar Control
Calendar Control allows you to select a date using graphical calendar display. I would like to list out the methods, properties and events of Calendar Control.
List of methods on Calendar Control
S.No.
List of Methods
01.
OnApplyTemplate
02.
ToString
List of Properties on Calendar Control
S.No.
List of Properties
01.
BlackoutDates
02.
CalendarButtonStyle
03.
CalendarDayButtonStyle
04.
CalendarItemStyle
05.
DisplayDate
06.
DisplayDateStart
07.
DisplayDateEnd
08.
DisplayMode
09.
FirstDayOfWeek
10.
IsTodayHighlighted
11.
SelectedDate
12.
SelectedDates
13.
SelectionMode
List of Events in Calendar Class
S.No.
List of Events
01.
DisplayDateChanged
02.
DisplayModeChanged
03.
SelectedDatesChanged
04.
SelectionModeChanged
Demo for using Calendar Control in WPF
Run Visual Studio 2015 in your PC and select File - New - Project.
Select Visual C# - Windows - WPF Application - Name your WPF Application and select the location where you need it to be saved and click on OK.
This will create the project names “CalendarWPF”.
Drag and drop the Calendar Tool in the Graphical Window of your Visual Studio as shown below.
You can find the below code on MainWindow.xaml once when you drag and drop the Calendar tool in your Graphical Window.
<Calendar HorizontalAlignment=
"Left"
Margin=
"144,91,0,0"
VerticalAlignment=
"Top"
/>
Run the WPF Application now by clicking on “Start” at the top pane of the Visual Studio 2015 to check the window with the calendar.
You can also rename the title for this window as were doing on the previous demo’s. Goto MainWindow.xaml and make the following changes on your code.
Existing Code on MainWindow.xaml
<Window x:Class=
"CalendarWPF.MainWindow"
xmlns=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=
"http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d=
"http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc=
"http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local=
"clr-namespace:CalendarWPF"
mc:Ignorable=
"d"
Title=
"MainWindow"
Height=
"350"
Width=
"525"
>
Code to be replaced on MainWindow.xaml
<Window x:Class=
"CalendarWPF.MainWindow"
xmlns=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=
"http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d=
"http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc=
"http://schemas.openxmlformats.org/markup-compatibility2006"
xmlns:local=
"clr-namespace:CalendarWPF"
mc:Ignorable=
"d"
Title=
"Calendar Window"
Height=
"350"
Width=
"525"
>
You can find the below changes on your Graphical Window, you can even try the same by checking your output when you run the WPF Application that you have developed.
Tips
You can also try all properties with help of the below code on Visual Studio for Calendar Control,
<Window x:Class=
"WPFCalenderControl.MainWindow"
xmlns=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=
"http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d=
"http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc=
"http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local=
"clr-namespace:WPFCalenderControl"
mc:Ignorable=
"d"
Title=
"Calendar Window"
Height=
"350"
Width=
"604"
>
<Grid>
<Calendar Margin=
"20"
SelectionMode=
"MultipleRange"
IsTodayHighlighted=
"false"
DisplayDate=
"1/1/2015"
DisplayDateEnd=
"1/31/2015"
SelectedDatesChanged=
"Calendar_SelectedDatesChanged"
xmlns:sys=
"clr-namespace:System;assembly = mscorlib"
>
<Calendar.BlackoutDates>
<CalendarDateRange Start=
"1/2/2015"
End=
"1/4/2015"
/>
<CalendarDateRange Start=
"1/9/2015"
End=
"1/9/2015"
/>
<CalendarDateRange Start=
"1/16/2015"
End=
"1/16/2015"
/>
<CalendarDateRange Start=
"1/23/2015"
End=
"1/25/2015"
/>
<CalendarDateRange Start=
"1/30/2015"
End=
"1/30/2015"
/> </Calendar.BlackoutDates>
<Calendar.SelectedDates>
<sys:DateTime>1/5/2015</sys:DateTime>
<sys:DateTime>1/12/2015</sys:DateTime>
<sys:DateTime>1/14/2015</sys:DateTime>
<sys:DateTime>1/13/2015</sys:DateTime>
<sys:DateTime>1/15/2015</sys:DateTime>
<sys:DateTime>1/27/2015</sys:DateTime>
<sys:DateTime>4/2/2015</sys:DateTime>
</Calendar.SelectedDates>
<Calendar.Background>
<LinearGradientBrush EndPoint=
"0.5,1"
StartPoint=
"0.5,0"
>
<GradientStop Color=
"#FFE4EAF0"
Offset=
"0"
/>
<GradientStop Color=
"#FFECF0F4"
Offset=
"0.16"
/>
<GradientStop Color=
"#FFFCFCFD"
Offset=
"0.16"
/>
<GradientStop Color=
"#FFD80320"
Offset=
"1"
/> </LinearGradientBrush>
</Calendar.Background>
</Calendar>
</Grid>
</Window>
Keynotes in Short
About Calendar Tools in WPF.
List of properties on Calendar Control.
List of methods on Calendar Control.
List of Events on Calendar Control.
Demo on using Calendar Control in WPF.
Sample code for methods, properties and events in WPF
Calendar Control Tools
Windows Presentation Foundation
Next Recommended Reading
Adding and Closing User Control To a Panel On WPF Window