原創|其它|編輯:郝浩|2012-12-04 10:53:42.000|閱讀 791 次
概述:Mindscape WPF Elements進程控制器提供了一個用于創建、查看、基于項目的日歷樣式的時間編輯的用戶界面。本文介紹了進程控件的一些使用,附加實例和源碼。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Mindscape WPF Elements進程控制器提供了一個用于創建、查看、基于項目的日歷樣式的時間編輯的用戶界面。一個進程調度可以基于一天、一周、或是以月來查看,并且提供了用于用戶選擇的視圖和在日期之間導航的的用戶界面,你也可以使用進程調度程序來顯示約會、任務、預定等等。
示例:
<ms:Scheduler x:Name="SchedulerControl" />
自定義添加和編輯行為:
當用戶創建了一個新的進程項目時,調度程序提出了ItemAdded事件,默認情況下,將顯示一個子窗口,用戶可以編輯新項目(如設置一個名、編輯時間、設置復發)。禁用默認行為,并顯示自己“添加項目”的用戶界面,來控制添加項目事件。如果你想要顯示默認的用戶界面是,但是依然需要在項目添加是得到通知,在AddScheduleItemEventArgs設置ShowDefaultEdito為true就行了。
設置進程
通過進程屬性,你可以訪問進程,查看進程類或者是更多的信息。使用添加項目的方法,來添加項目到進程中,或者是移除項目。
在項目中的每個項目由項目進程所體現,而這里面包含了起始時間、結束時間、項目名稱等信息。你也可以創建項目進程的子類來包含一些其他的信息,比如說任務調度的優先級等。
如下所示:
private void AddTryTask() { SchedulerControl.Schedule.AddItem(new ScheduleItem { StartTime = DateTime.Now.Date.AddHours(8), EndTime = DateTime.Now.Date.AddHours(9), Name = "Try WPF Elements" }); }
保存導入進程:
進程控件不是提供一個內置的方法來存儲或導入一個進程,主要是因為進程在通常情況下呢是被存儲在數據庫里面,允許查詢等,所以說存儲將依賴于數據庫設計,WCF 服務接口等。
若要保存或加載計劃,使用 Scheduler.Schedule 屬性,讀取該附表的內容,以便可以使用 Schedule.Items 屬性將它們存儲。如果要從存儲區加載時填充日程安排,使用 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); } }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件