|
…
<syncfusion:GanttControl x:Name="Gantt"
ItemsSource="{Binding ListaAttivita}"
ScheduleType="CustomDateTime"
CustomScheduleSource="{Binding CustomSchedule}"
…
ZoomChanged="Gantt_ZoomChanged"
</syncfusion:GanttControl>
… |
|
In MainWindows.xaml.cs
private void Gantt_ZoomChanged(object sender, ZoomChangedEventArgs args)
{
List<GanttScheduleRowInfo> currentSource = this.Gantt.CustomScheduleSource as List<GanttScheduleRowInfo>;
List<GanttScheduleRowInfo> newSource = new List<GanttScheduleRowInfo>();
foreach (GanttScheduleRowInfo info in currentSource)
{
newSource.Add(info);
}
double initialPixelPerUnit = 30;
double adjustment = ((args.ZoomFactor - 100) / 10) * 5;
newSource[currentSource.Count - 1].PixelsPerUnit = initialPixelPerUnit + adjustment;
this.Gantt.CustomScheduleSource = newSource;
args.Handled = true;
}
In ViewModel.cs
private List<GanttScheduleRowInfo> customSchedule;
public List<GanttScheduleRowInfo> CustomSchedule
{
get
{
return this.customSchedule;
}
set
{
this.customSchedule = value;
}
}
public ViewModel()
{
…
this.CustomSchedule = new List<GanttScheduleRowInfo>
{
new GanttScheduleRowInfo { TimeUnit = TimeUnit.Weeks},
new GanttScheduleRowInfo { TimeUnit = TimeUnit.Days, PixelsPerUnit = 30 }
};
} |
|
private void Gantt_ZoomChanged(object sender, ZoomChangedEventArgs args)
{
…
// To increase the schedule range padding dynamically.
if (args.ZoomFactor != 100)
{
if (this.Gantt.ScheduleRangePadding != 365)
{
this.Gantt.ScheduleRangePadding = 365;
}
}
else if (this.Gantt.ScheduleRangePadding != 14)
{
this.Gantt.ScheduleRangePadding = 14;
}
…
} |
|
private void Gantt_ZoomChanged(object sender, ZoomChangedEventArgs args)
{
…
// To scroll the gantt chart to particular date.
this.Gantt.ScrollGanttChartTo(DateTime.Today);
} |
|
private void Gantt_Loaded(object sender, RoutedEventArgs e)
{
…
sv2 = VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(GanttChart, 0), 0) as ScrollViewer;
sv2.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
this.visibleStartTime = this.GetVisibleStartDate(sv1.HorizontalOffset);
}
private void Sv1_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
..
this.visibleStartTime = this.GetVisibleStartDate(e.HorizontalOffset);
…
}
}
private DateTime GetVisibleStartDate(double offset)
{
…
double days = offset / dayWidth;
…
return this.Gantt.ActualStartTime;
}
private void Gantt_ZoomChanged(object sender, ZoomChangedEventArgs args)
{
…
// To scroll the gantt chart to particular date.
this.Gantt.ScrollGanttChartTo(this.visibleStartTime);
} |