Friday, October 29, 2010

What does this mean?  Is the class supported on Windows Phone?  Am I just not reading it right?

http://msdn.microsoft.com/en-us/library/system.globalization.hebrewcalendar(VS.95).aspx


Platform Notes

Silverlight for Windows Phone:
This type is present but is not supported on Windows Phone.
Version Information

Silverlight

Supported in: 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.0

HebrewCalendar on Windows Phone 7 - Gotcha in leap years

Try converting a hebrew calendar date in Elul in a leap year using this code:


            DateTime myDateTime = new DateTime(1995, 9, 1);
            DateTime returnDateTime;
            HebrewCalendar hebrewCalendar = new HebrewCalendar();
            int jyear;
            int jmonth;
            int jday;
            jyear = hebrewCalendar.GetYear(myDateTime);
            jmonth = hebrewCalendar.GetMonth(myDateTime);
            jday = hebrewCalendar.GetDayOfMonth(myDateTime);
            returnDateTime = hebrewCalendar.ToDateTime(5767, jmonth, jday, 0, 0, 0, 0);

This will cause an error as 5767 is not a leap year and there are only 12 months in a non leap year, and jmonth is 13 in the code above.

(Elul is month 12 in non leap years and month 13 in leap years).

Solution
If the beginning year is a leap year and the end year is not a leap year
and the month index is greater than 7 //Adar II
then move the month back one


If the beginning year is not a leap year and the end year is a leap year

and the month index is greater than 7 //Adar II
then move the month forward one


            bool isLeap1 = hebCal.IsLeapYear(hYear);
            bool isLeap2 = hebCal.IsLeapYear(year);
           if ((isLeap1 & !isLeap2) & hMonth > 7)
            { hMonth--; }

           if ((!isLeap1 & isLeap2) & hMonth > 7)
           { hMonth++; }




Links:
http://www.hebcal.com/converter/?hd=11&hm=Elul&hy=5771&h2g=Convert+Hebrew+to+Gregorian+date
http://msdn.microsoft.com/en-us/library/system.globalization.hebrewcalendar(VS.95).aspx

This is a good right up with some examples on the HebrewDate class in C#.
http://www.ziporah-greve.net/prog/jewish-csharp.html


Side note:
This became much clearer to me when I had to create example code from my code.

Wednesday, October 27, 2010

DateTime picker?

The DateTime picker is not in the original developer toolkit, but it is in a new download.

Silverlight for Windows Phone Toolkit - Sept 2010
http://silverlight.codeplex.com/releases/view/52297

Phone Emulator orientation and keyboard input

When using the phone emulator with the PC keyboard the Orientation of the app does not change.



Radio Button groups

  • There is no Tab Group box in the toolbox
    • Solution: use GroupName in the .xaml file
    • eg.
            <RadioButton Content="Male" Height="72" HorizontalAlignment="Left" Margin="293,102,0,0" Name="maleRadioButton" VerticalAlignment="Top" Checked="maleRadioButton_Checked"
                         GroupName="MyRadioBtnGroup"/>
            <RadioButton Content="Female" Height="72" HorizontalAlignment="Left" Margin="292,177,0,0" Name="femaleRadioButton" VerticalAlignment="Top" Checked="femaleRadioButton_Checked" 
                         GroupName="MyRadioBtnGroup"/>

The traditional way of dealing with multiple radio buttons, with "one checked" behaviour, is to put the Radio Buttons in a group box.  The Toolbox in the Windows Phone 7 Toolkit does not have a group box.


I was trying to do it programatically, and could not find a simple way to programatically set the state of the Radio Button, trying to use SetValue required a DependencyProperty...