Original: WPF Month view Control
Brief introduction
When you do an application, you need to make a calendar month view of the form. Do more trouble yourself, so look for the internet, found on the codeproject of this quick and simple WPF Month-view Calendar, but the background of the program is written in VB. Although I do not write VB, but reading can also understand a sorta. It is then rewritten as C #, making some improvements to make it more generic. As follows:
Used in a simpler way, declared in XAML, and then used in code. Support in the definition from daily matter interface and double-click events.
XAML declaration:
<Windowx:class= "Monthviewtest.mainwindow"xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"Xmlns:monthcontrol= "Clr-namespace:monthview.controls;assembly=monthview"Title= "MainWindow"Width= "$"Height= "All"> <Monthcontrol:monthcontrolx:name= "Testmonthcontrol" /></Window>
Background code uses:
usingMonthview.eventargs;usingSystem.Windows;namespacemonthviewtest{/// <summary> ///the interactive logic of MainWindow.xaml/// </summary> Public Partial classMainwindow:window { PublicMainWindow () {InitializeComponent (); //Event SourceTestmonthcontrol.datetimeevents =diarycache.diaries; //Event Interface Factorytestmonthcontrol.datetimeeventcontrolfactory=Newdiarybreifcontrolfactory (); Testmonthcontrol.dayblankdoubleclicked+=addnewdiary; } /// <summary> ///processing of a date control double-click/// </summary> /// <param name= "E" ></param> Private voidaddnewdiary (Dayeventargs e) {varDiary =NewDiary {happentime=E.daytime,}; varWND =NewDiarywindow {Diary=Diary, Title="Add a journal", Owner=Application.Current.MainWindow}; if(true==Wnd. ShowDialog ()) {DIARYCACHE.DIARIES.ADD (wnd. Diary); } } }}
Principle
The code structure is as follows:
The core code is in Daycontrol. The process of building the interface is as follows: Use System.Globalization.Calendar to calculate the total number of days of the month, and then calculate the total number of weeks based on the first day of the month. Add the week control of the corresponding week to the month control, and then place the day control for each day of the one month into its corresponding week control.
Cons: The list of items needs to be loaded into memory at once, and the code can be modified to load on demand with delegates. Control does not support generics, and if you do not need to use it in XAML, you can modify the code to support generics.
Code
Blog Park: Wpfmonthview.
Github:wpfmonthview.
WPF Month View Control