Enable didable weekends anc holidays

Hi,

if i click twice button 2 weekend and holiday are not visible.

Best regards
Gian Piero Truccolo

Attachment: ActivateDisactivateShowWeekendsHolidays_fbd0ae7a.zip

7 Replies 1 reply marked as answer

SS Sridevi Sivakumar Syncfusion Team May 27, 2021 12:54 PM UTC

Hi Gian Piero Truccolo,

Greetings from Syncfusion.

We have checked the reported query with provided sample and we found you have set false to gantt ShowWeekEnds and ShowHolidays properties all the time. So that weekends and holidays are not showing while click the button.

We have modified the sample and change the ShowWeekends, and ShowHolidays values dynamically and it's working as per below code snippet.
 
        private void ChangeSchedule_Click(object sender, RoutedEventArgs e) 
        { 
               Gantt.ShowWeekends = Gantt.ShowWeekends ? false : true; 
                Gantt.ShowHolidays = Gantt.ShowHolidays ? false : true; 
            } 
 



GI Gian May 27, 2021 01:24 PM UTC

Hi, 

i'm sorry for the inconvenience, this is the correct code and that gives me the error.

 private bool IsNumeric  = true;
        private void ChangeSchedule_Click(object sender, RoutedEventArgs e)
        {
            if (IsNumeric)
            {
                Gantt.ShowWeekends = true;
                Gantt.ShowHolidays = true;
                IsNumeric = false;
            }
            else
            {
                Gantt.ShowWeekends = false;
                Gantt.ShowHolidays = false;
                IsNumeric = true;
            }
        }

Replace it behind the window.

Best regards
Gian Piero Truccolo


SS Sridevi Sivakumar Syncfusion Team May 28, 2021 09:55 AM UTC

Hi Gian Piero Truccolo,

We have modified the button click code as per the shared code snippet and added GanttHolidayCollection to the Gantt control to show the holidays.

Now, when we click the button, Holidays and Weekends will get update dynamically. Please have a sample from the below link
https://www.syncfusion.com/downloads/support/directtrac/299320/ze/GanttSample-1508127010

Let us know if you need any further assistance.

Regards,
Sridevi S. 
 


Marked as answer

GI Gian May 28, 2021 10:01 AM UTC



SS Sridevi Sivakumar Syncfusion Team May 28, 2021 10:32 AM UTC

Hi Gian Piero Truccolo,

Sorry for the inconvenience caused.

Please have a sample from below link 

Let us know if you need any further assistance.

Regards,
Sridevi S. 
 



GI Gian May 28, 2021 12:13 PM UTC

Hi,

set this property in the viewmmodel

 private ObservableCollection<GanttHoliday> _CustomHolidays;
        public ObservableCollection<GanttHoliday> CustomHolidays
        {
            get
            {

                return _CustomHolidays;
            }
            set
            {
                _CustomHolidays = value;
                OnPropertyChanged();
            }
        } 


chaneg the constructor with this

public ViewModel()
        {
            Activities = new ObservableCollection<Processi>();
            //DATE SCHEDULE 
            CustomSchedule = new ObservableCollection<GanttScheduleRowInfo>
            {
                new GanttScheduleRowInfo { TimeUnit = TimeUnit.Weeks},
                new GanttScheduleRowInfo { TimeUnit = TimeUnit.Days, PixelsPerUnit = 30 }
            };
            //NUMERIC SCHEDULE 
            //CustomSchedule = GetInfo();

            GenerateDataSource();
            CustomHolidays = new ObservableCollection<GanttHoliday>();
            GanttHoliday h = new GanttHoliday();
            h.Day = new DateTime(2021, 5, 17);
            CustomHolidays.Add(h);
            h = new GanttHoliday();
            h.Day = new DateTime(2021, 5, 20);
            CustomHolidays.Add(h);
            h = new GanttHoliday();
            h.Day = new DateTime(2021, 5, 31);
            CustomHolidays.Add(h);
        }

and in the xaml  use this binding

Holidays="{Binding CustomHolidays}" 

and you will receive the null exception.

Best regards
Gian Piero Truccolo


SS Sridevi Sivakumar Syncfusion Team May 31, 2021 10:25 AM UTC

Hi Gian Piero Truccolo,

We have analyzed the shared code snippet and noticed that you have set Holiday collection as ObservableCollection<GanttHoliday>, but the Holiday collection's actual type is GanttHolidayCollection. Please refer below link for Holidays collection.

https://help.syncfusion.com/wpf/gantt/holidays-customization?cs-save-lang=1&cs-lang=csharp

So, please modify the type to GanttHolidayCollection as per the below code snippet

[ViewModel.cs]
 
  
 
private GanttHolidayCollection _CustomHolidays; 
public GanttHolidayCollection CustomHolidays 
{ 
    get 
    { 
  
        return _CustomHolidays; 
    } 
    set 
    { 
        _CustomHolidays = value; 
        OnPropertyChanged(); 
    } 
} 
 
  
public ViewModel() 
{ 
    … 
   CustomHolidays = new GanttHolidayCollection(); 
    GanttHoliday h = new GanttHoliday(); 
    h.Day = new DateTime(2021, 5, 17); 
    CustomHolidays.Add(h); 
    h = new GanttHoliday(); 
    h.Day = new DateTime(2021, 5, 20); 
    CustomHolidays.Add(h); 
    h = new GanttHoliday(); 
    h.Day = new DateTime(2021, 5, 31); 
    CustomHolidays.Add(h); 
} 

Let us know if you need any further assistance.

Regards,
Sridevi S.
 


Loader.
Up arrow icon