原創(chuàng)|其它|編輯:郝浩|2012-12-04 10:53:42.000|閱讀 791 次
概述:Mindscape WPF Elements進(jìn)程控制器提供了一個用于創(chuàng)建、查看、基于項目的日歷樣式的時間編輯的用戶界面。本文介紹了進(jìn)程控件的一些使用,附加實例和源碼。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Mindscape WPF Elements進(jìn)程控制器提供了一個用于創(chuàng)建、查看、基于項目的日歷樣式的時間編輯的用戶界面。一個進(jìn)程調(diào)度可以基于一天、一周、或是以月來查看,并且提供了用于用戶選擇的視圖和在日期之間導(dǎo)航的的用戶界面,你也可以使用進(jìn)程調(diào)度程序來顯示約會、任務(wù)、預(yù)定等等。
示例:
<ms:Scheduler x:Name="SchedulerControl" />
自定義添加和編輯行為:
當(dāng)用戶創(chuàng)建了一個新的進(jìn)程項目時,調(diào)度程序提出了ItemAdded事件,默認(rèn)情況下,將顯示一個子窗口,用戶可以編輯新項目(如設(shè)置一個名、編輯時間、設(shè)置復(fù)發(fā))。禁用默認(rèn)行為,并顯示自己“添加項目”的用戶界面,來控制添加項目事件。如果你想要顯示默認(rèn)的用戶界面是,但是依然需要在項目添加是得到通知,在AddScheduleItemEventArgs設(shè)置ShowDefaultEdito為true就行了。
設(shè)置進(jìn)程
通過進(jìn)程屬性,你可以訪問進(jìn)程,查看進(jìn)程類或者是更多的信息。使用添加項目的方法,來添加項目到進(jìn)程中,或者是移除項目。
在項目中的每個項目由項目進(jìn)程所體現(xiàn),而這里面包含了起始時間、結(jié)束時間、項目名稱等信息。你也可以創(chuàng)建項目進(jìn)程的子類來包含一些其他的信息,比如說任務(wù)調(diào)度的優(yōu)先級等。
如下所示:
private void AddTryTask() { SchedulerControl.Schedule.AddItem(new ScheduleItem { StartTime = DateTime.Now.Date.AddHours(8), EndTime = DateTime.Now.Date.AddHours(9), Name = "Try WPF Elements" }); }
保存導(dǎo)入進(jìn)程:
進(jìn)程控件不是提供一個內(nèi)置的方法來存儲或?qū)胍粋€進(jìn)程,主要是因為進(jìn)程在通常情況下呢是被存儲在數(shù)據(jù)庫里面,允許查詢等,所以說存儲將依賴于數(shù)據(jù)庫設(shè)計,WCF 服務(wù)接口等。
若要保存或加載計劃,使用 Scheduler.Schedule 屬性,讀取該附表的內(nèi)容,以便可以使用 Schedule.Items 屬性將它們存儲。如果要從存儲區(qū)加載時填充日程安排,使用 Schedule.AddItem 方法就行了。
下面的代碼提供了一個簡單的保存和加載使用 XML 示例,這例子可用于在客戶端機上獨立存儲中存儲的日程安排。
代碼如下:
private static void WriteSchedule(Stream stm, Schedule schedule) { XElement element = new XElement("Schedule", schedule.Items.Select(si => new XElement("Item", new XAttribute("Name", si.Name), new XAttribute("StartTime", si.StartTime), new XAttribute("EndTime", si.EndTime), si.IsRecurring ? new XElement("Recurrence", new XAttribute("StartDate", si.RecurrenceInfo.StartDate), new XAttribute("StartTime", si.RecurrenceInfo.StartTime), new XAttribute("Duration", si.RecurrenceInfo.Duration), new XAttribute("EndDate", si.RecurrenceInfo.EndDate), new XAttribute("EndType", si.RecurrenceInfo.EndType), new XAttribute("MaxOccurrences", si.RecurrenceInfo.MaxOccurrences), si.RecurrenceInfo.RecurrencePattern.ToXml() ) : null ))); element.Save(stm); } private static void ReadSchedule(Stream stm, Schedule schedule) { XDocument document = XDocument.Load(stm); IEnumerable<ScheduleItem> items = document.Elements("Schedule").Elements("Item").Select(e => new ScheduleItem { Name = (string)e.Attribute("Name"), StartTime = (DateTime)e.Attribute("StartTime"), EndTime = (DateTime)e.Attribute("EndTime"), RecurrenceInfo = e.Elements("Recurrence").Select(rel => new RecurrenceInfo ( (DateTime)rel.Attribute("StartDate"), (TimeSpan)rel.Attribute("StartTime"), (TimeSpan)rel.Attribute("Duration"), rel.Elements().First().ParseRecurrencePattern(), (RecurrenceEndType)(Enum.Parse(typeof(RecurrenceEndType), (string)rel.Attribute("EndType"), true)), (DateTime)rel.Attribute("EndDate"), (int)rel.Attribute("MaxOccurrences") )).FirstOrDefault() }); schedule.Clear(); foreach (ScheduleItem item in items) { schedule.AddItem(item); } }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件