我正在使用devExpress scheduler control。请注意我在以下代码中尝试实现的目的是为后面的代码添加一个recurance。在这个例子中,当我创建一个新约会时,我正在这样做。
我的窗口包含一个调度程序控件:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:dxsch="http://schemas.devexpress.com/winfx/2008/xaml/scheduler">
<dxsch:SchedulerControl Name="schedulerControl1" />
</Window>
背后的代码包括:
using System.Windows;
using DevExpress.XtraScheduler;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow() // Constructor
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
void MainWindow_Loaded(object sender, RoutedEventArgs e) // Fires when window loads
{
schedulerControl1.Storage.AppointmentsInserted += new PersistentObjectsEventHandler(Storage_AppointmentsInserted);
}
void Storage_AppointmentsInserted(object sender, PersistentObjectsEventArgs e) // fires when a new appointment is added
{
Appointment addedAppointment = null;
foreach (Appointment item in e.Objects)
addedAppointment = item;
/*
I want to set the reinsurance info in here!
I cant because RecuranceInfo = null!
*/
addedAppointment.RecurrenceInfo.Type = RecurrenceType.Hourly; // <- App Crashes
}
}
}
我不想绑定控件的recurrence属性。
换句话说如果我可以创建一个今天下午2点开始并且每天重复但没有结束日期的约会,那将是很棒的。我怎么能在后面的代码上创建该约会呢?
答案 0 :(得分:1)
答案在此链接中:http://documentation.devexpress.com/#WindowsForms/CustomDocument6201
基本上我必须这样做:
Appointment apt = schedulerControl1.Storage.CreateAppointment(AppointmentType.Pattern);
apt.Start = DateTime.Now;
apt.End = apt.Start.AddHours(2);
apt.Subject = "My Subject";
apt.Location = "My Location";
apt.Description = "My Description";
apt.RecurrenceInfo.Type = RecurrenceType.Daily;
schedulerControl1.Storage.AppointmentStorage.Add(apt);