Skip to main content Skip to footer

Check out the new Calendar for Windows Phone

In the new release of ComponentOne’s Studio for Windows Phone, we’re offering a new control: Calandar. I’d like to take a couple of minutes and show you some of the features of this new control and how you can quickly implement it into your existing Windows Phone applications. First, let’s look at adding the control to our XAML views:

<c1calendar:C1Calendar x:Name="cal1" MaxSelectionCount="14"  
WeekendBrush="LightGreen" Loaded="cal1_Loaded"  
DoubleTap="cal1\_DoubleTap"  DisplayDateChanging="cal1\_DisplayDateChanging">

At a glance, we see a couple of unique properties that make the calendar customizable for your needs. MaxSelectionCount refers to the number of days on the calendar that you can select at a time. By tapping and moving across an array of days, you can select those days and iterate against them in code. WeekendBrush lets you specify a particular color to distinguish weekend days from weekdays. Finally, we have event handlers for when the control is loaded, when we change the date (or month in this case), and when we double tap on a date on the calendar. Next, let’s take a look how we can integrate with data provided by the Windows Phone environment. Here is the implementation of the DoubleTap event.


private void cal1_DoubleTap(object sender, GestureEventArgs e)  
        {  
            // show the list of appointments for the bolded day  
            FrameworkElement fel = e.OriginalSource as FrameworkElement;  
            if (fel != null)  
            {  
                DaySlot slot = fel.DataContext as DaySlot;  
                if (slot != null && slot.IsBolded)  
                {  
                    DateTime date = slot.Date;  
                    Microsoft.Phone.UserData.Appointments appts = new Microsoft.Phone.UserData.Appointments();  
                    appts.SearchCompleted += (s, e1) =>  
                    {  
                        string message = date.ToShortDateString();  
                        if (IsEmulator)  
                        {  
                            message += "\\r\\nNo information when run on emulator";  
                        }  
                        else if (e1.Results.Count<Microsoft.Phone.UserData.Appointment>() == 0)  
                        {  
                            message += "\\r\\nNo events for some reason";  
                        }  
                        else  
                        {  
                            foreach (Microsoft.Phone.UserData.Appointment app in e1.Results)  
                            {  
                                message += "\\r\\n" + app.Subject;  
                            }  
                        }  
                        MessageBox.Show(message);  
                    };  

                    appts.SearchAsync(date, date.AddDays(1).AddSeconds(-1), null);  
                }  
            }  
        }  

Let's explore this code a little bit. When a user double taps on a day on the calendar, we'll pull the context of the particular day they tapped. With that information, we'll query the Appointment data on the phone itself to retrieve any appointments that might occur on that day. If we're running on the emulator, there won't be any appointments. If there are appointments, we just want to append them all into a single string to display to the user. What you might do with the data could be more glamorous. I'm only outlining a small use case here, but there are other great features you should know about: Gestures All the gestures you've come to love and expect on the Windows Phone are supported by the calendar. Cultures The calendar control will respect any culture supported by the .NET Framework. Styling We make it easy for you to distinguish between weekdays, weekends, or really any date that you want on the calendar. The headers and overall look of the control is also completely customizable. DataTemplates can be overridden so you can make the calendar your own. There you go! I hope that you're encouraged to check out the new Calendar for Windows Phone. This is just one of several new features in our 2012 v1 release. Take a few minutes and learn about all the other cool features!

MESCIUS inc.

comments powered by Disqus