GanttView.RequestTimescaleRulers Event
Occurs when timescale rulers are visually changed and allows you to edit timescale rulers. This is a routed event.
Namespace: DevExpress.Xpf.Gantt
Assembly: DevExpress.Xpf.Gantt.v24.1.dll
NuGet Package: DevExpress.Wpf.Gantt
Declaration
Event Data
The RequestTimescaleRulers event's data class is RequestTimescaleRulersEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Handled | Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs. |
NonworkingDayVisibility | Gets or sets the nonworking day visibility at a current zoom level. |
NonworkingTimeVisibility | Gets or sets the nonworking time visibility at a current zoom level. |
OriginalSource | Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs. |
RoutedEvent | Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs. |
Source | Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs. |
TimescaleRulers | Get or sets a collection of timescale rulers displayed at the current zoom level. |
Zoom | Gets the current zoom. |
The event data class exposes the following methods:
Method | Description |
---|---|
InvokeEventHandler(Delegate, Object) | When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs. |
OnSetSource(Object) | When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs. |
Remarks
The RequestTimescaleRulers event occurs on init, when the Gantt area is zoomed and when the TimescaleRulerCount property value is changed.
Handle the RequestTimescaleRulers event to dynamically change the following:
- a set of rulers displayed within the timescales (RequestTimescaleRulersEventArgs.TimescaleRulers)
- visibility of nonworking days and nonworking time (RequestTimescaleRulersEventArgs.NonworkingDayVisibility and RequestTimescaleRulersEventArgs.NonworkingTimeVisibility)
private void view_RequestTimescaleRulers(object sender, DevExpress.Xpf.Gantt.RequestTimescaleRulersEventArgs e) {
// Remove a ruler from timescale
e.TimescaleRulers.RemoveAt(1);
// Add a ruler that indicates hours
e.TimescaleRulers.Add(new DevExpress.Xpf.Gantt.TimescaleRuler(DevExpress.Xpf.Gantt.TimescaleUnit.Hour));
// Add a ruler that indicates 30 minute ranges
e.TimescaleRulers.Add(new DevExpress.Xpf.Gantt.TimescaleRuler(DevExpress.Xpf.Gantt.TimescaleUnit.Minute, 30));
// Nonworking dates and nonworking time are not indicated with a specific background
e.NonworkingDayVisibility = Visibility.Hidden;
e.NonworkingTimeVisibility = Visibility.Hidden;
}
The RequestTimescaleRulers
event allows you to add timescale rulers with custom formats:
- Create a class that implements IFormatProvider and ICustomFormatter interfaces.
In this class, specify the ruler’s text and format. The following code sample displays months or two-month ranges based on the zoom level:
public class CustomFormatProvider : IFormatProvider, ICustomFormatter { public static CustomFormatProvider GetFormatProvider(TimeSpan zoom) { return new CustomFormatProvider(zoom.Hours > 2 ? "{0:MMM}" : "{0:MMMM yyyy} - {1:MMMM yyyy}"); } public string FormatString { get; } public CustomFormatProvider(string formatString) { FormatString = formatString; } public object GetFormat(Type formatType) { if (typeof(ICustomFormatter) == formatType) return this; else return null; } public string Format(string format, object arg, IFormatProvider formatProvider) { var range = arg as DateTimeRange?; return range.HasValue ? string.Format(FormatString, range.Value.Start, range.Value.End) : null; } }
Add a new timescale ruler and pass your custom format to its FormatProvider property: