Posts tagged C#
Detecting theme on Windows Phone 7
0This blog post is going to teach you how do we detect if we are on dark or light theme on Windows Phone 7. I realised that this will be useful because I have quite some friends who are asking me about it because they didn’t get the right resources online. If you happened to come across a resource that asks you to get from App.xaml, that doesnt work anymore as its removed after the RC build.
Based on Theme Resources for Windows Phone, under Theme Visibility and Opacity.
By checking Resources, I am able to check if its Visible or Collapsed for the dark or White theme by doing this
Visibility isLight = (Visibility)Resources["PhoneLightThemeVisibility"]; // for light theme
Visibility isDark = (Visibility)Resources["PhoneDarkThemeVisibility"]; // for dark theme
Then we use if else to check,
if (isLight == System.Windows.Visibility.Visible)
{
//We are on light theme
}
Light Theme
or
if (isDark == System.Windows.Visibility.Visible)
{
//We are on dark theme
}
Dark Theme
Attached is a sample code to show how do I detect Windows Phone 7 theme, before the Mango buuild ( I am unsure if there is a change after Mango ).
Detect Theme on Windows Phone 7 Sample
How to use Back Button on Windows Phone 7
1Credit to Steven, http://www.sticapac.com for allowing me to post this up on my blog.
Recently, I worked on an app for the Windows Phone 7 platform and submitted it to the marketplace for certification. I’ve learnt many things and gained many insights after going through this process and would like to share one of these with you, developers and potential developers of the Windows Phone 7 platform.
Throughout this post, I will be making references to the official Windows Phone 7 Application Certification Requirements document (WP7ACR) which can be downloaded athttp://go.microsoft.com/?linkid=9730558.
Under Section 5.2.4 of the WP7ACR, clause a, it is stated that:
Pressing the Back button from the first screen of an application must exit the application.
Developers who are creating apps with multiple pages must give special attention to this clause because pressing the back button automatically brings the user to the previous page, regardless of whether the user is at the first screen or not. Consider the following example:
In this app, there are 2 pages. Page1 goes to Page2 via a button with the following logic:
NavigationService.Navigate(new Uri(“/Page2.xaml”, UriKind.Relative));
Page2 goes back to Page1 via a button with the following logic:
NavigationService.Navigate(new Uri(“/Page1.xaml”, UriKind.Relative));
Each time that line of code is executed, it is actually creating a new instance of the page defined under the new Uri. Therefore if the user navigates in this manner:
- User starts the app.
- User navigates to Page2 via button.
- User navigates to Page1 via button.
At this point in time, the user is at the first page of the application. If the user presses the back button, he will be brought back to Page2 instead of exiting the app, which is wrong and will result in a failure of the certification process.
There is no API in the Windows Phone 7 SDK similar to the Application.Exit() function found in the average C#.NET Windows Forms application. For this reason, we must overcome this problem by navigation by page hierarchy. That is to say, when the user navigates from Page2 to Page1 via the button, instead of treating Page1 as a new page, the developer should instead use this line of code for the navigation purpose from Page2 back to Page1:
NavigationService.GoBack();
By doing this, the developer is essentially coding the button to function exactly like what the back button does on the Windows Phone. In this way, the app will always exit when the back button is pressed on the first page because the first page is always the only record under the action history when the user is on the first page. The diagram will then look like this:
Therefore we have successfully adhered to Section 5.2.4 of the WP7ACR, clause a. This is how we can effectively use the Back button and pass certification for functions relating to the back button.
Windows 7 Workshop
0Met YangLin, Pratibha, Eugene and Alex there while I attend the Windows 7 Development workshop at SMU organised by SG Acad Team, MS Singapore. I have been following Jocelyn Villaraza‘s blog but never had a chance to see her in action and today, finally, i had. Pretty good presentation done by her.
I am gonna rewrite one of her guide for my school’s bootcamp. Hope to get it done when I am free next week ( After Monday ). I never knew that program was so cool.
Going to teach wushu tomorrow morning!
What programs to write?
0I am too addicted to facebook now?
Guo Hong now wants to write some simple application using C# but not sure what he can write.
What I will be doing next?
0Seems like its about 90% done.
I am looking to do a full HTML or CSS reference and tutorial website once I am done with my current website and promotion.
I have a few domains to use.
To do list:
-Upgrade my blog’s script
-C# boot camp #2 / #3 ( Its lying in my admin panel for very long already. )
-Disclaimer and About Me page.
-Clear up unused domains in my cPanel
-Clear up unused MySQL in my cPanel
C# Boot Camp ( Part 1)
0What is C#? ( Wiki to what is C# )
Anyway it was fun. 3 letters to summarise the whole UX ( User Experience ). Haha
This maybe useful for me in the future.
//This is how to comment in C#
//This is how to make a message box come out, Message.Show
//(CONTENT OF MESSAGE BOX, TITLE OF THE MESSAGE BOX)
Message.Show("Guo Hong", "Title")
In php, to add things on to a string variable, we do
$des = "Guo Hong is ";
$des .= "handome.";
but in C#,
string des = "Guo Hong is ";
des += "handome.";
Notice the += and .= ?
Haha, hopefully tomorrow will be more interesting!




