Saturday, June 25, 2011

Mr. WolfBytes featured on GrapeCity Russ Cam – Episode 14 SQL Saturday #77

Earlier this month when I was up doing some Windows Phone 7 training and a Windows Phone Garage up in Pensacola, Russell Fustino of GrapeCity shot a little video at the speakers dinner, looks like it turned out pretty good!  My ugly mug was featured in the intro for the video =D.

-twb

Windows Phone 7 – Quick Tip #30 – Quickly Save Configuration Settings

Today’s tip is a real simple one, you need to save some sort of configuration setting to some persistent storage mechanism.  You can certainly write the values out to a file with IsolatedStorageFile.GetUserStoreForApplication.  But let’s just say you just want to save a string or a number, it might be worthwhile to build up some sort of config or settings class and serialize that with DataContractSerializer but it might be easier to just use IsolatedStorageSettings.ApplicationSettings

ApplicationSettings has some nice static methods to act as a Key-Value pair local storage mechanism.  It even has a TryGetValue method so you can easily build some intelligence into initializing your settings.

Using ApplicationSettings is as simple as:

IsolatedStorageSettings.ApplicationSettings[“KEY”] = value

and

value = IsolatedStorageSettings.ApplicationSettings[“KEY”]

Just make sure you remember to call the save method after setting a new value.

IsolatedStorageSettings.ApplicationSettings.Save();

No rocket-science today, but this might be exactly what you need to shed a few lines of code from your application.

-twb

Sunday, June 19, 2011

Windows Phone 7 – Quick Tip #29 – Working with Cookies

Bad-News/Good News – First the bad news: if you are building a Windows Phone 7 application and need to access the cookies for a request/response you are out of luck.  The good news is your app can successfully maintain cookies set by the server between requests.  That is to say if you make a call to the server, the server sets some sort of cookie, you can replay that cookie back to the server.  The limitation is you just aren’t allowed access to the cookie jar for your own consumption (to mix metaphors a little).

It’s really simple, just create an instance System.Net.CookieContainer which I usually call something like CookieJar and set it on the request object or on your C# code that you generate as a proxy for your service call.

image

and

image

I had thought we had access to cookies in Mango, but after checking in the latest drop of the development tools, it still looks like we don’t.  If I hear differently, I’ll update this post.

-twb

Windows Phone 7 – Quick Tip #28 – Expand ListView Items to Full Screen

Let’s say you are building a Windows Phone 7 app that displays items in a list.  Within this list you want to display something that is right justified with the border of the list.  If we used the following XAML:

image

We end up with:

image

Which really isn’t what we want, we want the “Click Me” button right justified.

If we replace the above XAML with the followings snippet:

image

and note the following changes to the XAML:

  1. We added a resource to the grid that will be displaying the list of items.  It contains a style for the ListBoxItem with the key ListItem.  This sets the HorizontalContentAlignment=”Stretch”.
  2. Next we applied that style to the ItemContainerStyle=”{Static Resource ListItem}” of the list view.
  3. Finally if you noticed in the first chunk of XAML, we use a StackPanel.  A StackPanel only is as wide as it’s content.  We change this to a Grid which will take up the full width of the parent..

Now when we run our application we see the following which is what we expect:

image-twb