nav-left cat-right
cat-right

Windows Phone 7 – Speed Up Development with ...

Often times there is a routine, repetitive task that you perform during development to help you meet an end goal. For instance, a lot of applications have a login screen. Just a basic screen that requires you to enter your username / password, then click “Login”. Well, if you’re writing an application, pretty soon this entering of your credentials gets old. In order to relieve this pain, I’d like to revisit an old friend, the preprocessor directive.

A preprocessor directive can be used for conditional compilation. In other platforms, this conditional uses a separate preprocessor. However, C# the directives are processed as if there were only one. Altogether, C# has 14 preprocessor directives. To show how you can use a preprocessor directive to speed up your development, lets consider the login screen again.

If you have a basic page, you may be tempted to enter the credentials in your constructor like the following:

public Login()
{
  InitializeComponent();

  if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Emulator)
  {
  usernameTextBox.Text = "testUserName";
  passwordBox.Password = "testPassword";
  }
}

The problem here is the .xap file. If you publish this application, your test credentials will actually be stored in the code. Because of this, someone could use a tool like RedGate’s .NET Reflector and see your credentials. If you’re a solo developer, you may actually be using your real credentials which could open a personal pandora’s box for you.  To help you avoid this unfortunate situation, you could improve the previous code by doing the following:


public Login()
{
  InitializeComponent();

  #if DEBUG
  usernameTextBox.Text = "testUserName";
  passwordBox.Password = "testPassword";
  #endif
}

This approach will remove your credential code when you compile your application in Release mode. Something you should do before you submit your application to the Windows Phone Marketplace. The reason your credentials are removed is because of the special DEBUG directive. This directive is defined by Visual Studio be default. Basically, it means anytime your application is compiled under “Debug” configuration, the code in-between the #if DEBUG -> #endif directives will be included.

What is WinRT?...

This week during the Microsoft BUILD conference, WinRT was introduced. This set of APIs was introduced as part of the Windows 8 development stack. The immediate question I had was, “What is WinRT?”. I’ll try to share part of what I’ve learned about WinRT in this post. I’ll be sharing more as I learn.

WinRT is known as the “Windows Runtime”. Because every technology must have a shortened name for tweeting purposes, WinRT seems to be the standard, so can we all agree to use #winrt. :) . I know I’ll be on my Twitter feed. Before we continue, let’s take a look at a diagram that Steve Sinofsky presented during the Day 1 keynote:

 

One of the key items to recognize in this image is that WinRT is used for Metro Style apps. Whether those apps are written in XAML and [C|C++|C#|VB] or HTML/CSS and JavaScript, WinRT serves as the foundation. Metro Style apps are a key concept of Windows 8, which will include WinRT. It is also important to recognize that this runtime cannot be ported back to previous versions of Windows (i.e. Windows 7).

Personally, I really like the idea of classifying these apps as “Metro Style apps”. I think it helps give a set of APIs a brand. I think a brand helps make a set of APIs more approachable. I also like how Metro Style apps bring C and C++ devs to the XAML party. I also like the fact that the HTML/JS languages can be used. I’m anticipating some interesting new JavaScript libraries to emerge as a result of WinRT.

From what I can tell, as of the date of this post, WinRT consists of 109 new namespaces.  These namespaces share the Windows. prefix. They seem to be logically grouped under the following 14 categories:

  • ApplicationModel
  • Data
  • Devices
  • Foundation
  • Globalization
  • Graphics
  • Management
  • Media
  • Networking
  • Security
  • Storage
  • System
  • UI
  • Web

While this information isn’t very practical in nature, there’s more to WinRT than a single blog post. I’m going to try and post a lot more regularly around this topic. More practical type stuff. I will publicly say that I will NOT be writing a book on this topic. It looks like Pete Brown already has you covered in that respect :) Either way, WinRT seems pretty intriguing. What are your thoughts / questions / comments on WinRT?

Newline Character in XAML...

Have you ever wondered how to use explicitly place a newline character in XAML?All you need to do is enter ‘
’. For instance:


<TextBlock Text="This is content on the first line.&#x0a;This text actually goes on the second line!" />

Happy coding!

« Previous Entries