Probably this is the wrong approach to do it, because i have modified a little too much code to make it work. However this modification seem to do the job, soI post it (and maybe someone will post a better approach...)
Modifiedcode to achieve the a custom duration bar color (in italic the code, in bold my added parts)
=== Day.cs ===
private void stripAndAddEvent(Event e)
{
stripAndAddEvent(e.Start, e.End, e.PK, e.Name, e.Resource, e.DurationBarColor );
}
on the last line of the above called method:
events.Add(new Event(pk, start, end, name, resource, barColor));
=== DayPilotCalendar.cs ===
In the private fields of the class added:
private string dataBarColorField;
In renderEvent(...) added the e. to access the color of the event, instead one common for all events:
576: output.AddStyleAttribute("background-color", ColorTranslator.ToHtml(e.DurationBarColor));
in protected override void PerformDataBinding(IEnumerable retrievedData) added:
if (DataBarColorField == null || DataBarColorField == String.Empty)
throw new NullReferenceException("DataBarColorField property must be specified.");
and in the foreach loop, before items.Add
Color barColor = ColorTranslator.FromHtml(DataBinder.GetPropertyValue(dataItem, DataBarColorField, null));
=== DayPilotCalendarProperties.cs ===
[Category("Data")]
[Description("The name of the column that contains the bar color to use. ")]
public string DataBarColorField
{
get
{
return dataBarColorField;
}
set
{
dataBarColorField = value;
if (Initialized)
{
OnDataPropertyChanged();
}
}
}
=== Event.cs ===
using System.Drawing;
in the members:
public Color DurationBarColor;
public Event(string pk, DateTime start, DateTime end, string name) : this(pk, start, end, name, null)
{
this.DurationBarColor = Color.Red; // i think it is not used directly
}
public Event(string pk, DateTime start, DateTime end, string name, string resource)
{
this.PK = pk;
this.Start = start;
this.End = end;
this.Name = name;
this.Resource = resource;
this.DurationBarColor = Color.Blue; // this is the "default" color if not specified
}
/// <summary>
/// Constructor that uses the Duration Bar Color .
public Event(string pk, DateTime start, DateTime end, string name, string resource, Color durationColor)
{
this.PK = pk;
this.Start = start;
this.End = end;
this.Name = name;
this.Resource = resource;
this.DurationBarColor = durationColor;
}
=== End ==
To use it in the BindingDataTable.aspx.cs i can use something like this:
DataTable dt;
dt = new DataTable();
dt.Columns.Add("start", typeof(DateTime));
dt.Columns.Add("end", typeof(DateTime));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("barColor", typeof(string));
DataRow dr;dr = dt.NewRow();
dr["id"] = dView[i].Row["Cod"];
if (XXX)
dr["barColor"] = "red";
else
dr["barColor"] = "blue";