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.
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!
Hello,The WPF framework will first check whether there is a Style property set when it tries to locate the local style. If the local style is set, the Style provided as a window or application resource will not be used. You need to set the BasedOn property for that style and use the general style as a StaticResource to make sure both styles are applied.
If that is not the case in your scenario, please modify the sample project Tacho attached in his previous response to illustrate the issue with the styles not being applied so I can investigate the behavior further.
Great! Thank you!
This worked for me, although it altered the display more than I would have expected. Prior to this change I was hiding the ScheduleDateRangePresenter (Start/End time), but with this change it has come back. I also noticed that other styling, like font size and margin, are different as well
Within the xamSchedule.xaml styling file, I set the ScheduleDateRangePresenter Visibility to Collapsed, and I altered some of the standard font sizes and margins... which I think is being ignored now that I'm using the AppointmentPresenter_Loaded.
Is there a way to force the ScheduleDateRangePresenter Visibility programatically, or to make sure that all other styles (aside from the color change) still come through?
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.