I am not sure if this is by design, but I noticed if I create an Exception at runtime using a Custom Appointment and change a field, it doesn't update the UI until I do something like change the View and come back. I have found a hack where I delete the appointment and then immediately re-add it. But is there a way to tell the UI to update after adding an Exception? Here is some example code I made to show that on a button click, I am just creating an Exception and adding it to an Appointment. I want to change the border color. But it doesn't change until I change the Schedule View and come back.
public MainWindow()
{
InitializeComponent();
DataContext = this;
var resourceType = new ResourceType("Location") { AllowMultipleSelection = true };
var room1 = new Resource("Room 1");
var room2 = new Resource("Room 2");
var room3 = new Resource("Room 3");
resourceType.Resources.Add(room1);
resourceType.Resources.Add(room2);
resourceType.Resources.Add(room3);
var groupDescription = new GroupDescriptionCollection
{
new DateGroupDescription(),
new ResourceGroupDescription { ResourceType = "Location" }
};
ScheduleView.GroupDescriptionsSource = groupDescription;
ScheduleView.ResourceTypesSource = new ResourceTypeCollection { resourceType };
var app = new CustomeAppoinment { Start = new DateTime(2015, 05, 07, 4, 50, 00), End = new DateTime(2015, 05, 07, 6, 50, 00), Subject = "Test" };
RecurrencePattern pattern;
RecurrencePatternHelper.TryParseRecurrencePattern("FREQ=DAILY;COUNT=10", out pattern);
app.RecurrenceRule = new RecurrenceRule(pattern);
app.Resources.Add(room1);
app.Resources.Add(room2);
Appointments.Add(app);
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
var appointment = Appointments[0].Copy();
var customAppointment = new CustomAppointment
{
Start = appointment.Start,
End = appointment.End,
RecurrenceRule = appointment.RecurrenceRule,
Subject = appointment.Subject,
IsAllDayEvent = appointment.IsAllDayEvent,
UniqueId = Guid.NewGuid().ToString(),
BorderColor = Brushes.Green
};
foreach (var item in appointment.Resources)
{
var resource = item as Resource;
customAppointment.Resources.Add(resource);
}
Appointments[0].RecurrenceRule.AddException(Appointments[0].Start, customAppointment);
//Workaround. Remove and re-add the appointment to update the UI.
var appt=Appointments[0];
Appointments.Remove(appt);
Appointments.Add(appt);
}
private ObservableCollection<CustomAppointment> _appointments = new ObservableCollection<CustomAppointment>();
public ObservableCollection<CustomAppointment> Appointments
{
get { return _appointments; }
set { _appointments = value; RaisedPropertyChanged("Appointments"); }
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisedPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
var e = new PropertyChangedEventArgs(propertyName);
handler(this, e);
}
}