Mindscape WPF Elements中進程控件的使用

  原文轉載自慧都控件網:http://www.evget.com/zh-CN/Info/catalog/18212.html 

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);
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章