1 0
post icon

Selecting an Item in a ComboBox after Adding Items

When adding items to a Combobox dynamically you might notice that setting an items IsSelected = true directly aftewards fails to work.

For example, this fails to select the first item in the ComboBox:

ComboBoxItem cbi;
 
foreach (string category in Categories)
{
    cbi = new ComboBoxItem();
    cbi.Content = category;
   CategoryCB.Items.Add(cbi);
}
 
if (CategoryCB.Items.Count > 0)
{
    cbi = (ComboBoxItem)CategoryCB.Items[0];
    cbi.IsSelected = true;
}

The way to do this is via the SelectedIndex property off your ComboBox control:

if (CategoryCB.Items.Count > 0)
{
    CategoryCB.SelectedIndex = 0;
}

Thanks,

–Mike

Leave a Comment
post icon

Detecting Users Win7 Mobile Theme Color

If you want your Win7 mobile application to mimic the theme/system colors your users phone is using you can do so through the the use of the Theme Resources.

For example, the color of each of the tiles in your phone is called the “Accent” color. To obtain this color simply call:

SolidColorBrush brush=Application.Current.Resources["PhoneAccentBrush"] as SolidColorBrush;

Background and Foreground colors:

background = Application.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush;
foreground = Application.Current.Resources["PhoneForegroundBrush"] as SolidColorBrush;


For more details on the other colors available see: http://msdn.microsoft.com/en-us/library/ff769552(VS.92).aspx

Thanks,

–Mike

Leave a Comment
post icon

Win7 Mobile: Uniquely Identifying a Device or User

If you need to uniquely identify the phone or device your application is running on you can do so via the Microsoft.Phone.Info.DeviceExtendedProperties namespace. The following code shows how to do this:

byte[] id = (byte[]) DeviceExtendedProperties.GetValue("DeviceUniqueId");
string value = BitConverter.ToString(id);


“DeviceUniqueID” returns a byte array (20 bytes in length).

It will look something like this:

"FF-7E-85-36-AE-18-55-1A-59-1B-90-C8-54-FA-31-39-E0-6B-95-44"

If you want to uniquely identify a user instead of the device itself you can do so using the Microsoft.Phone.Info.UserExtendedProperties namespace. The following code shows how to do this:

string anid = UserExtendedProperties.GetValue("ANID") as string;
string anonymousUserId = anid.Substring(2, 32);

For example, say you want to send top scores for your game to your web service. You will  need to have a unique, static identifier that you can associate with the user of the phone (regardless of what device they are using at any given time) such that the next time you save their score it will use the same, unique identifier that no one else can have.

Thanks,

–Mike

Leave a Comment
29. Dec, 2010
post icon

Silverlight: Reading from a File Contained in your XAP

The approach you take to reading from a file that is contained in your XAP is different from one you might take reading a file that is on a server or one that you have copied over to your ClientBin (which could be done using WebClient).

To do this first add the file to your Silverlight project and set the Build Action for this file to be of type Resource.

Next, create a URI that points to the file like I do below and create a StreamResourceInfo from the URI.

Uri uri = new Uri("SilverlightApplication6;component/MyFile.txt", UriKind.Relative)
StreamResourceInfo streamInfo = Application.GetResourceStream(uri); 


Replace SilverlightApplication6 above with the namespace used in your Silverlight application. Replace MyFile.txt with the name of your file you added to your Silverlight project.

Next, get the Stream object from StreamResourceInfo and you can then create a StreamReader from the Stream.

if (null != streamInfo)
{
    Stream stream = streamInfo.Stream;
    StreamReader sr = new StreamReader(stream);
 
    string line = String.Empty;
    while ((line = sr.ReadLine()) != null)
    {
    }
}


From there, you are good to go!

–Mike

Leave a Comment
28. Dec, 2010
post icon

Funny Sounds, Radio Streams & Japanese – Win7 Mobile Apps

Well, I am having a lot of fun on my vacation creating applications in Silverlight for the Win7 mobile phone.

My latest published application allows you to play a variety of sounds including some funny, obnoxious ones that will find some good laughs at a party.

The application is called “Funny Sounds” and can be downloaded via the marketplace. Direct Zune link: http://social.zune.net/redirect?type=phoneApp&id=10fb5adc-390b-e011-9264-00237de2db9e

Let me know if there are any sounds you would like to have in this app to make your friends laugh!

I have two other applications I am about to publish soon next week.

The first is a program that allows you to listen to radio stations that support SHOUTCast streams. This application allows you to pick a genre and a sub-genre to help you find the radio station that is right for you. Screenshots:

image image

Finally, if you are interested in learning Japanese you will love my next application. Titled “PeraPera” (which means “fluent” in Japanese), this application allows you to study Kanji, Hiragana, Katakana as well as vocabulary. Before I got into Computer Science, Japanese was my passion and I spent over 5 years in Japan studying Japanese. I have always wanted to make a program like this and the Win7 Mobile Platform was the perfect place. Couple sneak preview screenshots below:

image image

Thanks,
–Mike

Leave a Comment