Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1375
Colors for different Appointments
posted

Using the XamSchedule in MVVM, is there a way to programmatically assign colors to different appointments? 

i.e.

Appointment apt = new Appointment();
if (myItem.type == "Sports")
{
       apt.Color = Colors.Blue;
}

Parents
  • 6365
    Offline posted

    Hello PMac,

    In order to change the fill color of an appointment in the XamSchedule (for example when using XamOutlookCalendarView), an approach I can suggest you is to simply get the respective Path element of the AppointmentPresenter element (visual representation of the Appointment) and set it's Fill property.

    For example:

    XAML:


    <ig:XamOutlookCalendarView.Resources>
        <Style TargetType="{x:Type igPrim:AppointmentPresenter}">
            <EventSetter Event="Loaded" Handler="AppointmentPresenter_Loaded" />
        </Style>
    </ig:XamOutlookCalendarView.Resources>

    Code-behind:


    void AppointmentPresenter_Loaded(object sender, RoutedEventArgs e)
    {
        var appointmentPresenter = (sender as AppointmentPresenter);
        var activitySubject = (appointmentPresenter.Activity as Appointment).Subject as string;

        if (activitySubject == "HR Consulting")
        {
            var mainGrid = Utilities.GetDescendantFromType(appointmentPresenter, typeof(Grid), false) as Grid;
            var innerGrid = Utilities.GetDescendantFromType(mainGrid, typeof(Grid), false) as Grid;

            var borderPath = Utilities.GetDescendantFromType(innerGrid, typeof(Path), false) as Path;
            borderPath.Fill = new SolidColorBrush(Colors.DarkOrange);
        }
    }

    I have attached a sample application, that uses the approach from above.

    If you have any further questions on the matter, please let me know.

    xamSchedule_sample.zip
Reply Children
No Data