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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Is it possible to create a customize the AppointmentLoadedEventArgs?

Thread ID:

Created:

Updated:

Platform:

Replies:

126992 Oct 20,2016 09:37 AM UTC Dec 8,2016 01:00 PM UTC Xamarin.Forms 3
loading
Tags: SfSchedule
Luuk
Asked On October 20, 2016 09:37 AM UTC

Hey,

I am currently working on a application that loads data from our servers with appointments. These appointsments have multiple properties in which the regular ScheduleAppointment can't provide our needs. 

For example the ScheduleAppointment properties are:

- subject
- starttime
-endtime

etc

What we have done is create a custom class that inherits the ScheduleAppointment class (Code below). This custom variant of the Appointment class contains some properties that we need for example:

- Finished (if a appointment is finished or not)


C# (ScheduleAppointment)
namespace BNApp.CustomRenderers
{

  

    public class BNScheduleAppointment : ScheduleAppointment 
    {



        /// <summary>
        /// Gets or sets the <c>ShowLocation</c> property.
        /// </summary>
        public static readonly BindableProperty ShowLocationProperty = Create(p => p.ShowLocation, "", BindingMode.Default, null, ShowLocationPropertyChanged, null, null, (CreateDefaultValueDelegate<BNScheduleAppointment, string>)null);







        /// <summary>
        /// Property which state depends on whether the Appointment has been finished. 
        /// </summary>
        /// <value> This property depends on <see cref="Aktie.Afgehandeld"/></value>
        public bool Finished;
        public List<Color> ColorCollection = new List<Color>();









        public BNScheduleAppointment()
        {
            CreateColorCollection();
        }


        /// <summary>
        /// The <c>Color</c> property is used to set the Color for the Appointment. This is a bindable property.
        /// The <c>Color</c> property is set to <value>Green</value> when the the value of <c>Finished</c> is set to true, otherwise it's color is set to red.
        /// <para>
        /// The properties can be changed by modifying the ColorCollection. [0] == true , [1] == false.  
        /// </para>
        /// </summary>
        /// <value>This property takes the <see cref="P:Syncfusion.SfSchedule.XForms.ScheduleAppointment.Color" /> And <seealso cref="Finished"/> value.</value>
        public new Color Color
        {

            get { return (Color)this.GetValue(ScheduleAppointment.ColorProperty); }
            set
            {
                if (Finished)
                {
                    this.SetValue(ScheduleAppointment.ColorProperty, ColorCollection[0]);
                }
                else if (!Finished)
                {
                    this.SetValue(ScheduleAppointment.ColorProperty, ColorCollection[1]);
                }
                //else if (!Finished && Color != Color.Default)
                //    this.SetValue(ScheduleAppointment.ColorProperty, (object)value);

            }
        }


        /// <summary>
        /// The <c>Location</c> property is used to set the location for the Appointment. This is a bindable property.
        /// </summary>
        /// <value>This property takes the <see cref="T:System.String" /> value.</value>
        public string ShowLocation
        {
            get
            {
                return (string)this.GetValue(BNScheduleAppointment.ShowLocationProperty);
            }
            set
            {
                this.SetValue(BNScheduleAppointment.ShowLocationProperty, (object)value);
                
            }
        }

        private static void ShowLocationPropertyChanged(BindableObject bindable, string oldValue, string newValue)
        {
            (bindable as BNScheduleAppointment).OnPropertyChanged(BNScheduleAppointment.ShowLocationProperty.PropertyName);
        }














        /// <summary>
        /// Method that will give the customer freedom to change the color to whatever they want. This is a method used for later.
        /// </summary>
        /// <param name="color"></param>
        /// <param name="e"></param>
        public void SetColor(Color color, SelectedItemChangedEventArgs e)
        {
            switch (e.ToString())
            {
                case "FinishedColor":
                    ColorCollection.RemoveAt(0);
                    ColorCollection.Insert(0, color);
                    break;
                case "UnfinishedColor":
                    ColorCollection.RemoveAt(1);
                    ColorCollection.Insert(1, color);
                    break;
            }

        }


        /// <summary>
        /// Method that creates colors and adds this to the list.
        /// [0] is Green, [1] is Red.
        /// </summary>
        private void CreateColorCollection()
        {

            ColorCollection.Add(Color.FromHex("#00ff00"));
            ColorCollection.Add(Color.FromHex("#ff0000"));
        }
    }

}
 
The following code works and allows our appointments to change color depending on the state in which ''IsFinished'' bool is set.

What we are trying to do right now is inherit the OnAppointmentLoadedEvent and customize this to accept our Appointment class, so we can use this event to for example show a image when the appointment IsFinished.

Only the problem is when we inherit and create the two classes we can't seem to trigger the OnAppointmentLoadedEvent when set to our BNAppointmentEventArgs. (Code Below)

C# BNAppointmentLoadedEventArgs 

namespace BNApp.CustomRenderers
{

    /// <summary>
    /// Custom class of the AppointmentLoadedEvent. The only thing changed is the usages of the BNScheduleAppointment instead of the regular ScheduleAppointment.
    /// </summary>
    public class BNAppointmentLoadedEventArgs : AppointmentLoadedEventArgs
    {


        public new AppointmentStyle appointmentStyle { get; set; }


        public new BNScheduleAppointment appointment { get; set; }

        public new View view { get; set; }

        public new Rectangle Bounds { get; set; }

        public BNAppointmentLoadedEventArgs()
        {
            this.appointmentStyle = new AppointmentStyle();
            
        }
    }

    
}

C# BnSchedule which inherits the SfSchedule

This class implements all sfschedules properties and methods. Also overrides the loaded event with a new one containing the BNAppointmenteventargs instead of Appointmenteventargs. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Syncfusion.SfSchedule.XForms;
using Xamarin.Forms;

namespace BNApp.CustomRenderers
{
    public class BNSchedule : SfSchedule 
    {
        

        ///// <summary>
        ///// AppointmentTemplateChanged event is raised while Appointments Changed.
        ///// </summary>
        
        public new event OnAppointmentLoadedEventHandler OnAppointmentLoadedEvent;
      


        public BNSchedule()
        {
            

          
        }

        



        public void OnAppointmentLoaded(BNAppointmentLoadedEventArgs args)
        {
            // ISSUE: reference to a compiler-generated field
            if (this.OnAppointmentLoadedEvent == null)
                return;
            // ISSUE: reference to a compiler-generated field
            this.OnAppointmentLoadedEvent((object)this, (BNAppointmentLoadedEventArgs)args);
        }


       

        public new delegate void OnAppointmentLoadedEventHandler(object sender, BNAppointmentLoadedEventArgs args);

    }





Luuk
Replied On October 20, 2016 10:01 AM UTC

To continue the previous qeustion (ran out of character space)


When using the new OnLoadedEvent it won't trigger when a appointment is shown sadly. When swiping to a certain date with a appointment it won't trigger the new event that accepts BNAppointments.


C# code behind (dayview)

 // does not get in here
        private void OnLoadedTestMethod(object sender, BNAppointmentLoadedEventArgs args)
        {
      
            if (args.appointment.Subject.Equals("Luuks test afspraak ") && args.appointment.Finished)
            {
                Button but = new Button();       
                but.BackgroundColor = Color.Aqua;
                but.Text = "doei";
                but.Image = "Menu.png";
                args.view = but;
            }
        }


We tried to use the regular method without using a own class and inheriting and just by casting our custom appointmenteventargs this will throw a null and our BNLoadedEventArgs will show the following text when debugging:  Unknown identifier: BNAppointmentLoadedEventArgs

C# casting examples:

    private void OnLoadedTestMethod(object sender, AppointmentLoadedEventArgs args)
        {
           
            var c = args as BNAppointmentLoadedEventArgs;

            var d = args.appointment as BNScheduleAppointment;

            
            if (c.appointment.Finished)
            {
                // does not work c == null
            }

            if (d.Finished)
            {
                // does not work b == null
            }

Both ways give us a null and will stop the application from further executing. Are we doing something wrong or something we are not supposed to do? 

Is this work in progress that will be added later on since being able to customize a entire appointment with custom properties would be very nice to have.



Cheers,

Luuk Jongebloet

Luuk
Replied On December 6, 2016 11:27 AM UTC

Still no answer I would like to read my custom properties of a appointment. I have a custom appointment with IsGroup property that I want to be able to trigger a group icon on.

When I try to trigger the OnAppointmentLoadedEvent and use a convert to convert and cast it as a BNAppointmentLoadedEvent(Custom one) that has a get to the BNAppointment (Custom Appointment) it will give me null.


Hopefully you can help me with this one

Subburaj Pandian Veluchamy [Syncfusion]
Replied On December 8, 2016 01:00 PM UTC

Hi Luuk,

We sincerely apologize for the inconvenience caused.

We have created a support incident under your account to track the status of this issue. Please log on to our support website to check for further updates.

https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents

Please let us know, if you have any query.

Regards,
Subburaj Pandian V.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;