Telerik UI for WPF?下载30天免费试用

特殊和只读槽位

使用RadScheduleView您可以定义特殊的和只读的槽,并对它们应用不同的样式。您只需要准备一个Slot对象集合并将其赋值给它SpecialSlotsSource属性。

每个Slot都有以下属性:

  • 开始-槽位的开始日期。

  • 结束-槽位的结束日期。

  • 资源—定义槽位的资源的集合。

  • RecurrencePattern-定义该槽位是否重复显示几天。

  • IsReadOnly-当设置为真正的槽位被禁用。

当插槽被禁用时,您不能在其中创建、编辑、删除或拖放约会。禁用插槽中的现有约会处于只读模式-单击约会时仍会显示编辑约会对话框,但无法编辑其属性。只读槽应用了灰色样式,但可以使用SpecialSlotsStyleSelector进行更改。

SpecialSlotsStyleSelector允许您为特殊槽应用单独的样式。您可以将此功能用于工作/非工作时间、假日、休息日等。

本文将介绍以下示例:

为非工作时间设置单独的样式

将给定资源的所有插槽设置为只读

在某些情况下,当使用大量的特殊插槽时,可能会有一些性能RadScheduleView控件中的问题。为了在使用特殊和只读槽时不损失性能,您应该记住以下措施:

  • 填充仅在可见范围内的slot。
  • 如果一个Slot同时在多个资源中,不要为每个资源创建单独的Slot,而是将资源分配给该Slot。
  • 如果一个Slot是循环的,不要创建许多不同的单独的Slot,而是创建一个循环的Slot。
  • 将slot视为appointment,则存在相同的性能主体。

为非工作时间设置单独的样式

  • 首先,你应该创建Slot对象的集合,并设置它们的recurrenceppattern属性:

var NonWorkingHours = new ObservableCollection();DateTime start = new DateTime(2010, 1,1,8,0,0);DateTime end = new DateTime(2010, 1,1,18,0,0);NonWorkingHours。Add(new Slot(end, start.AddDays(1)) {RecurrencePattern = new RecurrencePattern(null, RecurrenceDays. adddays)。星期一|复归日。周二|复归日。星期三|复归日。周四,RecurrenceFrequency。每周,1,null, null)});NonWorkingHours。Add(new Slot(end, start.AddDays(3)) {RecurrencePattern = new RecurrencePattern(null, RecurrenceDays. adddays)。星期五,RecurrenceFrequency。每周,1,null, null)});
  • 然后创建ScheduleViewStyleSelector类:

公共类SpecialSlotStyleSelector: ScheduleViewStyleSelector {private Style nonworkingHourStyle;public Style NonworkingHourStyle {get{返回this.nonworkingHourStyle;}设置{this。nonworkingHourStyle = value;}} public override Style SelectStyle(对象项,DependencyObject容器,ViewDefinitionBase activeViewDefinition){返回this.NonworkingHourStyle;}}
并定义样式:

    < /当地:SpecialSlotStyleSelector >
  • 最后,将它们绑定到SpecialSlotsSource和SpecialSlotsStyleSelector属性:

…< / telerik: RadScheduleView >
结果如下:

特殊的位置

将给定资源的所有插槽设置为只读

例如,让我们定义以下资源类型:

        …< / telerik: RadScheduleView >
  • 你可以像这样为“Team”资源创建只读槽的集合:

var ReadOnlySlots = new ObservableCollection();Slot readonlylot = new Slot() {Start = DateTime。MinValue, End =日期时间。MaxValue, IsReadOnly = true};readOnlyslot.Resources。添加(new Resource("Team", "Calendar"));ReadOnlySlots.Add (readOnlyslot);

添加到Slot的Resources集合和ResourceTypesSource中的ResourceType对象的对象类型需要匹配。这在场景中非常重要IResource接口实现。

  • 并将其分配给ScheduleView的SpecialSlotsSource属性:

…< / telerik: RadScheduleView >
只读槽看起来像这样:

只读的插槽

注意,EditAppointmentDialog甚至显示在只读槽中可视化的约会。为了防止它,订阅RadScheduleView的ShowDialog事件:

并在事件处理程序中取消它:

private void scheduleView_ShowDialog(对象发送器,ShowDialogEventArgs e) {var appointmentDialog = e. dialogviewmodel as AppointmentDialogViewModel;if (appointmentDialog != null && appointmentDialog. isreadonly) {e.Cancel = true;}}
请查看在线演示看特殊槽在行动。
在本文中
Baidu
map