blazor-devexpress-dot-blazor-dot-dxscheduler-13321fcd.md
The style-src: unsafe-inline CSP directive is not compatible with the Style event argument. Consider using the DevExpress.Blazor.SchedulerHtmlCellDecorationEventArgs.CssClass event argument as a safer alternative. Refer to the following help topic for additional information:
Content Security Policy (CSP).
Allows you to customize the appearance of Scheduler cells.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
[Parameter]
public Action<SchedulerHtmlCellDecorationEventArgs> HtmlCellDecoration { get; set; }
The HtmlCellDecoration event's data class is SchedulerHtmlCellDecorationEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| CellType | Specifies the Scheduler cell’s type. |
| CssClass | Assigns a CSS class to the Scheduler cell. |
| Intervals | Specifies the interval(s) to which the Scheduler cell belongs. |
| Resources | Specifies resources associated with the Scheduler cell. |
| Style | Specifies the name of an HTML style attribute applied to the cell. |
Handle the HtmlCellDecoration event to customize the appearance of Scheduler cells. In the event handler, use the event argument’s CellType property to identify the processed cell’s type. The following are available:
The event argument’s Intervals property defines the interval(s) to which a cell belongs. The Resources property specifies resources associated with the cell or contains an empty resource item if no resources are assigned.
Use the following properties to customize the cell’s appearance:
The following example customizes time cells in the interval between 13 and 14 hours and all date headers:
@using Data
<DxScheduler StartDate="@DateTime.Today"
DataStorage="@DataStorage"
HtmlCellDecoration="OnHtmlCellDecoration">
<DxSchedulerWeekView ShowWorkTimeOnly="true"></DxSchedulerWeekView>
</DxScheduler>
@code {
DxSchedulerDataStorage DataStorage = new DxSchedulerDataStorage() {
AppointmentsSource = RecurringAppointmentCollection.GetAppointments(),
AppointmentMappings = new DxSchedulerAppointmentMappings() {
Type = "AppointmentType",
Start = "StartDate",
End = "EndDate",
Subject = "Caption",
AllDay = "AllDay",
Location = "Location",
Description = "Description",
LabelId = "Label",
StatusId = "Status",
RecurrenceInfo = "Recurrence"
}
};
void OnHtmlCellDecoration(SchedulerHtmlCellDecorationEventArgs args) {
if (args.CellType == SchedulerCellType.TimeCell && 13 <= args.Intervals.Start.Hour
&& args.Intervals.Start.Hour < 14)
args.CssClass = "my-background";
if (args.CellType == SchedulerCellType.DateHeader)
args.Style = "background-color: rgb(224, 211, 245);";
}
}
.my-background {
background-color: lightgray;
}
public class Appointment
{
public Appointment() { }
public int AppointmentType { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public string Caption { get; set; }
public string Description { get; set; }
public string Location { get; set; }
public int Label { get; set; }
public int Status { get; set; }
public bool AllDay { get; set; }
public string Recurrence { get; set; }
}
public static partial class AppointmentCollection {
public static List<Appointment> GetAppointments() {
DateTime date = DateTime.Today;
var dataSource = new List<Appointment>() {
new Appointment {
Caption = "Install New Router in Dev Room",
StartDate = date + (new TimeSpan(0, 10, 0, 0)),
EndDate = date + (new TimeSpan(0, 12, 0, 0)),
Label = 6,
Status = 1
},
new Appointment {
Caption = "Upgrade Personal Computers",
StartDate = date + (new TimeSpan(0, 13, 0, 0)),
EndDate = date + (new TimeSpan(0, 14, 30, 0)),
Label = 1,
Status = 1
},
new Appointment {
Caption = "Website Redesign Plan",
StartDate = date + (new TimeSpan(1, 9, 30, 0)),
EndDate = date + (new TimeSpan(1, 11, 30, 0)),
Label = 1,
Status = 1
},
new Appointment {
Caption = "New Brochures",
StartDate = date + (new TimeSpan(1, 13, 30, 0)),
EndDate = date + (new TimeSpan(1, 15, 15, 0)),
Label = 8,
Status = 1
},
new Appointment {
Caption = "Book Flights to San Fran for Sales Trip",
StartDate = date + (new TimeSpan(1, 12, 0, 0)),
EndDate = date + (new TimeSpan(1, 13, 0, 0)),
AllDay = true,
Label = 8,
Status = 1
},
new Appointment {
Caption = "Approve Personal Computer Upgrade Plan",
StartDate = date + (new TimeSpan(2, 10, 0, 0)),
EndDate = date + (new TimeSpan(2, 12, 0, 0)),
Label = 8,
Status = 1
},
new Appointment {
Caption = "Final Budget Review",
StartDate = date + (new TimeSpan(2, 13, 0, 0)),
EndDate = date + (new TimeSpan(2, 15, 0, 0)),
Label = 1,
Status = 1
},
new Appointment {
Caption = "Install New Database",
StartDate = date + (new TimeSpan(3, 9, 45, 0)),
EndDate = date + (new TimeSpan(3, 11, 15, 0)),
Label = 6,
Status = 1
},
new Appointment {
Caption = "Approve New Online Marketing Strategy",
StartDate = date + (new TimeSpan(3, 12, 0, 0)),
EndDate = date + (new TimeSpan(3, 14, 0, 0)),
Label = 1,
Status = 1
},
new Appointment {
Caption = "Customer Workshop",
StartDate = date + (new TimeSpan(4, 11, 0, 0)),
EndDate = date + (new TimeSpan(4, 12, 0, 0)),
AllDay = true,
Label = 8,
Status = 1
},
new Appointment {
Caption = "Prepare 2015 Marketing Plan",
StartDate = date + (new TimeSpan(4, 11, 0, 0)),
EndDate = date + (new TimeSpan(4, 13, 30, 0)),
Label = 1,
Status = 1
},
new Appointment {
Caption = "Brochure Design Review",
StartDate = date + (new TimeSpan(4, 14, 0, 0)),
EndDate = date + (new TimeSpan(4, 15, 30, 0)),
Label = 1,
Status = 1
},
new Appointment {
Caption = "Create Icons for Website",
StartDate = date + (new TimeSpan(5, 10, 0, 0)),
EndDate = date + (new TimeSpan(5, 11, 30, 0)),
Label = 1,
Status = 1
},
new Appointment {
Caption = "Launch New Website",
StartDate = date + (new TimeSpan(5, 12, 20, 0)),
EndDate = date + (new TimeSpan(5, 14, 0, 0)),
Label = 8,
Status = 1
},
new Appointment {
Caption = "Upgrade Server Hardware",
StartDate = date + (new TimeSpan(6, 11, 0, 0)),
EndDate = date + (new TimeSpan(6, 13, 30, 0)),
Label = 8,
Status = 1
}
};
return dataSource;
}
}
See Also