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; }
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); }}
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.
Hello.
Is it possible to assign that event in c# only? In my application I had to create my XamMonthView in c#, without using XAML.
My goal is to set custom colors to individual appointments, and I really can't figure out how to do that.
Thanks in advance!