Hi,
We are using XAMCalendar. We added some styles for BackGround Color. But In Some case we want to refresh the Calendar or reload. Is there any way to reload or refresh the Calendar for showing default calendar view.We have already used UpdateLayout and UpdateDefaultStyle. But its not working.
Please let us aware.
Thanks.
Hello Kanwar,
What calendar default view are you referring to? Do you mean the view without your background color styling? If so, just remove your styles from whatever Resources collection they currently exist. This is assuming you are using implicit styles in order to apply your background color style. If you remove the style the control should automatically revert back to what it was before. Take a look at my attached sample. In it I have a style that changes the background color of the calendar. When I click on the remove button it removes the style and the color reverts back to the default.
Thanks for your support. Right now we are using XAMCalendar and for Background and Foreground we have added Converter along with we have combo Box which provide color code. Also we have datePicker for showing Start date, End Date.
For Example: First we select color code from combo. Next we select Start Date that will start from calendar minimum date and End Date will be Maximum Date of calendar. Suppose we select today date 5/10/2016 as Min calendar Start Date. and End Date 05/13/2016 will be set as Max Calendar Date. As we select Max date from Date Picker in converter we find color code and It will change background and Foreground color. (First Time working fine.)
Second Time If we select other color code again set same Min (5/10/2016) Max(05/13/2015) Date. In this scenario converter are not calling even we set the same date. We have noticed date in this scenario calendar is not calling Background Converter until or unless we select different dates from Picker.Overall If we reload or refresh the Calendar again somehow we can fulfill or requirement.
Solution for removing resources is not working proper way.
Thanks for your support.
Hi Kanwar,
Ok, so you have converters attached to the max date property and when the max date is changed your converter will change the background and foreground color. Is that correct?
Why not just bind the XamCalendar Background and Foreground directly to some color property in your view model? Then you can have some logic in your view model that will change the color based on the MinDate and MaxDate properties that you also have in your view model. I'm not sure why you need to use a converter for what you described.
Either way, your converter is not firing again because your DatePicker value did not change. If the value does not change then no property changed notification will fire and your converter won't trigger. Converters are triggered by property change notifications. So if you want to "refresh" the calendar then you need to trigger a property change notification on the property that your converter is attached to. I.e.:
If your binding looks like this:
"{Binding Path=MaxDate, Converter={StaticResource MyConverter}}"
You need to trigger a property changed notification on the MaxDate property:
OnPropertyChanged("MaxDate");
Hopefully MaxDate is a property in your view model. If you are binding directly to the DatePicker's SelectedDate property then you won't be able to trigger the property changed notification without actually changing the date. I recommend just having the MaxDate and MinDate properties in your view model.
Thanks for your support. But is there any way to change background and Foreground color of Calendar Day instead of whole calendar without using converter. We want to change background and Foreground only individual or some dates.
Thanks
Sorry, it wasn't clear that you needed the background and foreground to change only on specific calendar days. For that you will need to use a style which means you need to manually trigger the converter to fire by triggering a property changed notification. I'll assume that you have a MaxDate property in your view model and that your binding that has the converter is attached to the MaxDate property. To trigger a refresh just trigger the notification on MaxDate. I.e.:
void NotifyPropertyChanged(string propertyName){ if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));}
NotifyPropertyChanged("MaxDate");
Make sure your view model has implemented INotifyPropertyChanged.
For that I would suggest just defaulting the Min and Max dates to the start and end of the year. (use whatever years you want to start with)
MinDate = new DateTime(2016, 1, 1);MaxDate = new DateTime(2016, 12, 31);
This will let your calendar show all the months and then your users can change the min and max through the DatePickers on screen which will then adjust the calendar accordingly.
Thanks for your wonderful support. only one thing I wish to know that If Max date binds in View Model then first time while loading of calendar not showing all calendar Months. Initial or first time loading of calendar we want to show all calendar moths as default view of calendar after that If we select picker date then we can set Max date and Min Date from View Model.Only First time while loading of calendar want to show all months in calendar.
Right now if we bind Max and Min date in ViewModel then Initial loading of calendar not showing all months. Please let us aware how we can set default view or can display all months in calendar at first time.