WPF monthly View Control and wpf View Control

Source: Internet
Author: User

WPF monthly View Control and wpf View Control
Introduction

When you create an application, you need to create a calendar month view. I had trouble doing it myself, so I went online and looked for it. On CodeProject, I found this Quick and Simple WPF Month-view Calendar, but the background of the program was written in VB. Although I don't know how to write VB, I can understand it as well. So I changed it to C # and made some improvements to make it more universal. As follows:

<Window x: 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 =" 800 "Height =" 600 "> <monthControl: MonthControl x: Name =" TestMonthControl "/> </Window>

Background code usage:

Using MonthView. eventArgs; using System. windows; namespace MonthViewTest {/// <summary> // MainWindow. interaction logic of xaml // </summary> public partial class MainWindow: Window {public MainWindow () {InitializeComponent (); // The Event source TestMonthControl. dateTimeEvents = DiaryCache. diaries; // item interface factory TestMonthControl. dateTimeEventControlFactory = new DiaryBreifControlFactory (); TestMonthControl. dayBlankDoubleClicked + = AddNewDiary ;} /// <summary> /// double-click processing of the date control /// </summary> /// <param name = "e"> </param> private void AddNewDiary (dayEventArgs e) {var diary = new Diary {HappenTime = e. dayTime ,}; var wnd = new DiaryWindow {Diary = diary, Title = "add Diary", 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 page creation process 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 number of weeks on the first day of the month. Add the week control of the corresponding week number to the month control, and then add the day control corresponding to the day of the month to the corresponding week control.

Disadvantage: The item list needs to be loaded to the memory at a time. You can modify the code and use the delegate to load it as needed. Controls do not support generics. If you do not need to use them in XAML, you can modify the code to make them support generics.

Code

For the code, see WPFMonthView.

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.