WPF Month View Control

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.