Rants and Raves

Thanks for visiting my blog!

Phoney Windows Phone 7 Project Now Available!
Phoney Windows Phone 7 Project Now Available!
February 25, 2011

Url: http://phoney.codeplex.com/

UPDATE: Phoney now has a NuGet package.  Search on NuGet to add Phoney to your project!

I started this project when I found I had a number of small classes that I’d built for my Windows Phone 7 application so I thought it was time to share. here is the information on the new library.

It is currently in a very early Alpha stage, but I expect to have it at a release version by MIX 11 (Mid-April). Let me know what you think!

**Project Description **

This is a project that contains several classes and controls for use with Windows Phone 7 applications. There are plans for:

  • Standard Set of Converters
  • Several Controls
  • BitlyHelper
  • TwitterHelper
  • PhoneLogger
  • ObservableObject
  • FadingMessage class

Exposing all the Phone Resources (e.g. PhoneTextSizeLarge) as staticly typed accessors

Current Version is 0.1.

Only the following features are included:

  • BitlyHelper
  • PhoneLogger
  • FadingMessage
  • ObservableObject
  • Phone Resources

Examples:

**BitlyHelper class **

Simple class for shortening URI’s using your own Bit.ly API Key/username:

BitlyHelper.SetCredentials("MYBITLYAPIKEY", "MYBITLYUSERNAME");
BitlyHelper.Shorten("http://phoney.codeplex.com", (result, error) =>
  {
    if (error != null)
    {
      MessageBox.Show(string.Concat("Error Shortening Url: ", 
                                    error.Message));
    }
    else
    { 
      MessageBox.Show(result, 3000);
    }
  });

**FadingMessage class **

This class is to create messages that show up as a popup that fades in and fades out. For simple messages:

FadingMessage.ShowTextMessage("Saved...");

You can control the look and contents of the message by supplying your own UI objects:

FadingMessage msg = new FadingMessage()
{
  MessageToShow = theMessage,
  VerticalAlignment = VerticalAlignment.Top,
  HorizontalAlignment = HorizontalAlignment.Right
};
msg.Show(3000); // 3 seconds

**PhoneLogger class **

This class is to save a simple log file in Isolated Storage and can retrieve the contents of the log on demand:

PhoneLogger.LogError("Test Logging Message");

var log = PhoneLogger.LogContents;

**ObservableObject class **

This is an abstract class that supports the INotifyPropertyChanged interface for ease of hand-building objects that need observation.

public class MyObject : ObservableObject
{
}

**Phone Resources **

All of the known phone resources have accessors to give you strongly-typed access to the phone-based resources. Static Classes include:

  • PhoneColors
  • PhoneBrushes
  • PhoneFontSizes
  • PhoneFontFamilies
  • PhoneTextStyles
  • PhoneThicknesses
var theContainer = new Border()
{
  Background = PhoneBrushes.PhoneContrastBackgroundBrush,
  BorderBrush = PhoneBrushes.PhoneBorderBrush,
  BorderThickness = PhoneThicknesses.PhoneBorderThickness,
  CornerRadius = new CornerRadius(5)
};

theContainer.Child = new TextBlock()
{
  Margin = PhoneThicknesses.PhoneMargin,
  TextWrapping = TextWrapping.Wrap,
  Style = PhoneTextStyles.PhoneTextNormalStyle,
  Foreground = PhoneBrushes.PhoneAccentBrush,
  Text = message
};

In addition a PhoneTheme class that gives you a simple way to test for which theme (light or dark) the phone is using:

if (PhoneTheme.IsDarkTheme)
{
  // Change something because it's dark
}
else
{
  // Change it because it's light
}

What do you think?