We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Impossible to create Appointments from a list of Events

Hello i need help to add appointments from a list of objects. With a static list it seems ok. But when i try to generate the list dynamically nothing happened.


The Class-----------------------------------

public class Event : INotifyPropertyChanged

{

    private DateTime from, to;

    private string eventName;

    private bool isAllDay;

    private TimeZoneInfo startTimeZone, endTimeZone;

    private Brush background;

    private string notes;

........

}

the XAML -------------------------

 <scheduler:SfScheduler View="Month" ShowWeekNumber="True"

                           ShowNavigationArrows="False"

                           DisplayDate="{Binding DisplayDate}"

                           FirstDayOfWeek="Monday"

                           AllowedViews="Day,Week,WorkWeek,Month,TimelineDay,TimelineWeek,TimelineWorkWeek,TimelineMonth,Agenda"

                           TodayHighlightBrush="Red"

                           AppointmentsSource="{Binding Events}">


        <scheduler:SfScheduler.AppointmentMapping>


            <scheduler:SchedulerAppointmentMapping

                Subject="EventName"

                StartTime="From" EndTime="To"

                Background="Background" IsAllDay="IsAllDay"

                StartTimeZone="StartTimeZone"

                EndTimeZone="EndTimeZone" />


        </scheduler:SfScheduler.AppointmentMapping>

        <scheduler:SfScheduler.BindingContext>

            <viewmodel:SchedulerPage2ViewModel/>

        </scheduler:SfScheduler.BindingContext>


    </scheduler:SfScheduler>


The ViewModel -----------------------------

[QueryProperty(nameof(ListManifs), nameof(ListManifs))]

public partial class SchedulerPage2ViewModel : BaseViewModel

{

  private ObservableCollection<Manif> listManifs = new();

    public ObservableCollection<Manif> ListManifs

    {

        get { return listManifs; }

        set {

            listManifs = value;

            if (listManifs.Count != 0)

            {

               this.IntializeAppoitments();

            }

            OnPropertyChanged(nameof(ListManifs));

            }

    }

    /// <summary>

    /// Method to initialize the appointments.

    /// </summary>

    private void IntializeAppoitments()

    {

 foreach (Manif manif in ListManifs)

        {

            var meeting = new Event();

            meeting.From = manif.Date_start;

            meeting.To = manif.Date_end;

            meeting.EventName = manif.Name;

            meeting.Background = Colors.Red //this.colorCollection[randomTime.Next(10)];

            meeting.IsAllDay = (manif.Type == "Festival") ? true : false;

            meeting.Notes = "Test";  //this.noteCollection[randomTime.Next(10)];

            meeting.StartTimeZone = TimeZoneInfo.Local;

            meeting.EndTimeZone = TimeZoneInfo.Local;

            this.Events.Add(meeting);


        }

}

}




8 Replies

MA Mackenson March 8, 2023 12:33 PM UTC

my files


Attachment: my_files_543e0ce7.zip


SS SaiGanesh Sakthivel Syncfusion Team March 8, 2023 01:51 PM UTC

Hi Mackenson,


#Regarding Creating the Schedule appointment using List of events

We could not replicate the reported scenario from our end. We have prepared the sample as per the given information and checked the sample from our side. Please refer to the tested sample in the attachment.


Please check the sample and let us know if you still facing the same issue? If not, please modify the sample based on your scenario and revert us back with the following details,

.

  • Share the issue replicated steps or videos.


It will be helpful for us to check on it and provide you with the solution as soon as possible.


Regards,
SaiGanesh Sakthivel


Attachment: SchedulerMAUI_4711130a.zip


MA Mackenson March 8, 2023 02:44 PM UTC

Hello SaiGanesh Sakthivel,

My problem is that i provide Data from navigator then retrieve it in my page with QueryPropertyAttribute.


So let's say that :

That i have a list of Objects in Page1 then i send to Page2 in order to see them in a scheduler.


Page1ViewModel

[RelayCommand]

async Task SeeInScheduler()

{

if (ListManifs == null)

return;

await Shell.Current.GoToAsync(nameof(Page2), true, new Dictionary

{

{"ListManifs", ListManifs }

});

}


Page2ViewModel

[QueryProperty(nameof(ListManifs), nameof(ListManifs))]

public partial class Page2ViewModel : BaseViewModel

{

private ObservableCollection listManifs = new();

public ObservableCollection ListManifs

{

get { return listManifs; }

set

{

listManifs = value;

if (listManifs.Count != 0)

{

Events = new ObservableCollection();

foreach (Manif manif in ListManifs)

{

var ev = new SchedulerAppointment

{

StartTime = manif.start ,

EndTime = manif.end,

Subject = manif.Name,

Background = new SolidColorBrush(Color.FromArgb("#FFFC571D"))

};

Events.Add(ev);

}

}

OnPropertyChanged(nameof(ListManifs));

}

}


public Page2ViewModel ()

{

Events = new List();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ListManifs is still empty in the constructor cause it will be loaded only with OnAppearing()

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

}

}


So to summarize, the sheduler is not working when the Events collection is not initialized during the constructor public Page2ViewModel() . I cannot initialize my Events collection cause its only loaded with protected override void OnAppearing(). When i did it from the setter of ListManifs the scheduler has already been initialized so nothing will be show.

In other words, the function OnAppearing is triggered only when the page layout is fully loaded.

I don't know what to do to solve this.




SS SaiGanesh Sakthivel Syncfusion Team March 9, 2023 12:45 PM UTC

Hi Mackenson,


We were unable to replicate the reported scenario based on the given information. We attempted to prepare a sample using the given information, but the provided code snippet was missing some files, preventing us from creating a simple sample and testing the scenario on our end. Could you please modify the sample to make it runnable and share the replication steps and a video demonstrating the reported scenario, so we can check it from our end?


Attachment: SchedulerMAUI_3413065d.zip


MA Mackenson March 9, 2023 03:57 PM UTC

Hello  Sakthivel,

i recreate the sample in order to see the exact problem.

Please find the attached file.


Attachment: SchedulerMAUI_fd319e8b.zip


SS SaiGanesh Sakthivel Syncfusion Team March 10, 2023 01:07 PM UTC

Hi Mackenson,


The reported scenario is the sample level issue. We suggest removing the binding context for the scheduler control to overcome the reported scenario, as the binding context for the page is already set to the control during navigation. Please refer to the following code snippet for your reference.


Code snippet

<scheduler:SfScheduler View="Month" ShowWeekNumber="True"

                ShowNavigationArrows="True" x:Name="Scheduler"

                DisplayDate="{Binding DisplayDate}"

                AllowedViews="Day,Week,WorkWeek,Month,TimelineDay,TimelineWeek,TimelineWorkWeek,TimelineMonth,Agenda"

                TodayHighlightBrush="Red"

                AppointmentsSource="{Binding Events}">

<scheduler:SfScheduler.AppointmentMapping>

    <scheduler:SchedulerAppointmentMapping

    Subject="EventName"

    StartTime="From" EndTime="To"

    Background="Background" IsAllDay="IsAllDay"

    StartTimeZone="StartTimeZone"

    EndTimeZone="EndTimeZone" />

</scheduler:SfScheduler.AppointmentMapping>

<!--<scheduler:SfScheduler.BindingContext>

    <viewmodel:Page2ViewModel/>

</scheduler:SfScheduler.BindingContext>-->

</scheduler:SfScheduler>


Please refer to the modified sample in the attachment. Please let us know if you have any concerns.


Attachment: SchedulerMAUI_729d2bea.zip


MA Mackenson replied to SaiGanesh Sakthivel March 10, 2023 02:45 PM UTC

Hello  Sakthivel,

thanks a lot. My problem has been solved.

You are the man !!!!



SS SaiGanesh Sakthivel Syncfusion Team March 13, 2023 12:05 PM UTC

Mackenson,


We are glad to know that the provided solution is resolved the query. Please let us know if you need any further assistance. 


Loader.
Live Chat Icon For mobile
Up arrow icon