Hi.
I am using the calendar control on a page in a WP7 app. I have a data template for the calendar which displays some summary text for each date of the month where the user has entered some data for.
Currently I am allowing the user to double tap on a date. This takes the user to a page where they can enter data for the selected date, save and then return back to the calendar page. My problem is that I cannot get the calendar to show the updated entry, UNLESS I scroll to the next or previous calendar month and then scroll back to the current visible calendar month. I know that the data is in the list, however when the user returns to the page I cannot get the DateTextConverter class to get the data for the current month.
I guess basically I do not know how to force the data template binding the calendar to refresh. Is there some way that I can tell the calendar to refresh / requery the data for the current month when the user returns to the calendar page. I have tried doing things like UpdateLayout and instantianting the page again such as below with no luck:
This basically gets the data list again, which I already have anyway but tried it anyway.
CalendarPageViewModel = new CalendarPageViewModel();
DataContext = CalendarPageViewModel;
I noticed when I scroll the calendar, then it always goes back and calls the DateTextConverter class and hence renders the calendar with the updated data. I have some snippets of code below to try and help visualize what I am trying to do.
This gets called when user scrolls the calendar and will get the data that I need. Then when I scroll back to the current month the below gets called again and the current month will render the info, this time including the new entry as well.
public class DateTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
DateTime CurrentDate = (DateTime)value;
CalendarSummaryData CalendarSummaryData = CalendarPageViewModel.CalendarSummaryDataList.Where(x => x.Date == CurrentDate.Date).FirstOrDefault();
if (CalendarSummaryData == null) return string.Empty;
return CalendarSummaryData.RatingText;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
throw new NotImplementedException();
A snippet of the data template looks something like this below, though for the complete view refer to the attached project and look at the CalendarPage.xaml for a detailed overview. I would really appreciate some help on this as I am sure its quite easy, but am missing the point. I have it all working nicely, just want the calendar to render with the latest data when the user returns back to calendar page.
<phone:PhoneApplicationPage.Resources>
<local:DateColorConverter x:Key="DateColorConverter"/>
<local:DateTextConverter x:Key="DateTextConverter"/>
Style TargetType="igPrim:CalendarDayButton" x:Key="BaseCalendarDayStyle">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Bottom" />
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter.Value>
<ControlTemplate TargetType="igPrim:CalendarDayButton">
...
<TextBlock
Margin="5,2,0,0"
FontSize="15"
Text="{Binding Converter={StaticResource DateTextConverter}}"/>
<ContentControl x:Name="DayNumber" IsTabStop="False" Margin="5,0,0,10"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ButtonDataTemplate}"
HorizontalAlignment="Left" VerticalAlignment="Bottom" />
Grid>
ControlTemplate>
Thank you for your feedback. I reallu liek your code and I thinks it's very good. Also I prefer to use it on my guide on my website