My Favorite RegEx Builder

Posted in Development with tags , on October 12, 2011 by piotrp is a fantastic tool that allows you to start with a string you want to parse and provides an in-browser wizard for developing a regEx that parses it.

Unlike most regEx builders, which are really regEx testers, this tool lets you click on patterns it recognizes within the text and generates an appropriate regEx automatically. No need to re-remember regEx syntax yet again.

Once you have defined the regEx you want, the tool will allow you to grab the regEx in whatever syntax you like, making integration into coding projects a snap.


Great post on extending VS context menus

Posted in Uncategorized on September 29, 2011 by piotrp

Great post on fitting text content in XAML ListBox

Posted in Uncategorized with tags , , , on September 29, 2011 by piotrp

Check out Pete Brown’s great post on making Text containers behave in List Boxes.

I found this while dealing with text boxes that ignored the width of their ListBox container. Thanks Pete!

Blend’s PreCompiled Application Assemblies

Posted in Development with tags on February 17, 2011 by piotrp

I ran into a bug in my code that was causing Blend to crash perpetually. I addressed the bug in my code and relaunched Blend, but the problem persisted. After spending some time with my favorite search engine I ran across an interesting post:

Perpetual Expression Blend Crashes

In this post Nick says:

The solution: Delete the bin/obj folders from your application and open in Blend (of course after fixing the code issue). Blend will then be forced to do a new build of the application that should no longer raise the exception.

But where are the bin/obj folders in question? Using Mark Russinovich’s Process Explorer I was able to see that Blend loaded my application’s assemblies from two interesting locations:

  • C:\Users\<USERNAME>\Documents\Visual Studio 2010\SolutionName\ProjectName\Bin\
  • C:\Users\<USERNAME>\AppData\Local\Microsoft\Expression\Blend\Project Assemblies

The first directory is the Bin directory for my project, generated by Visual Studio and shared by Blend. The second is a bit more interesting. It seems to contain machine-generated copies of my assemblies intended for use specifically by Blend [this is an assumption based on the gibberish paths found in this directory].

Though the bug I ‘m running into [it has something to do with my use of the Reactive framework] is not yet fixed, I at least now know what to delete once the fix is found.

Binding Bing Maps Credentials Provider to a Resource Dictionary in Expression Blend

Posted in Development with tags , , , , on February 11, 2011 by piotrp

While building a Windows Phone 7 application that uses Bing Maps I saw myself going down a path where I was duplicating data. Namely, the Bing Maps ApplicationIdCredentialsProvider ApplicationID property must be set to an application-unique value on each instance of the map control. You can learn about obtaining a Bing Maps Key here.

Since I was using multiple map controls I was duplicating the value of my Application ID across my application. Since I’m teaching myself to build application declaratively using XAML I decided to eliminate my duplicate data using a Resource Dictionary. To make things more interesting, I chose to create and bind to the dictionary using Expression Blend for Windows Phone instead of editing source code directly.

Step 1: Create a Resource Dictionary

Creating a resource dictionary in Blend is quite easy. Just right-click on your project name and select Add New Item… and then select Resource Dictionary.


Step 1: Add New Item…
Step 2: Resource Dictionary

Step 2: Create an Application ID Resource

The first time I tried this step I could not figure out how to use the Blend UI and reverted to writing raw XAML by hand [more on this below].

Add your Application ID to an Existing Map Control

To start, find an existing Bing Map control in your application and make sure it has the Bing Maps Key set correctly. To do this:

  • Click on the Map Control
  • Load the Properties Pane
  • Paste [or type very carefully…] your Application ID into the first CredentialsProvider box.


Once you enter your key and press Enter blend will add your key to the Map’s XAML. It also replaces the Key you entered in the Properties Pane with the Type name of the CredentialsProvider object it used and fills in the small box to the right of the field:


Add the Application ID to the Resource Dictionary

With your Map’s CredetialsProvider defined you can now use Blend to refactor your application by extracting the Application ID to your Resource Dictionary. This step is even more simple than the last:

  1. Click the little white box to the right of the CredetialsProvider field and select Convert to New Resource
  2. Define your Resource
    1. Set the name to something like BingMapsAppID
    2. Set the Define In control to Resource dictionary
    3. Select your resource dictionary from the drop down
    4. Click OK

And that’s it! Blend will now automatically update your source code for the Map control to add a StaticResource binding. Blend will also add your Application ID, along with the rest of the CredentialsProvider, to your ResourceDictionary. Check out the XAML source for both for details!

Step 3: Apply the Static Resource to Other Maps

Now that the Static Resource is available you need to take advantage of it by using it anywhere where your Application ID is needed. To do this, find your remaining Map controls. On each control click the little box to the right of the first CredentialsProvider field you see. Hover over Local Resource and select BingMapsAppID. That’s it!



How I expected to use the Resource Dictionary

I’m not used to tools being quite so… streamlined. Typically, editing resources means:

  • Go into the resource file
  • Figure out how to add the right type of resource
  • Add the resource
  • Use the resource across your app

Blend takes a different, and in my opinion better, approach. You create your resource using the designer for the first instance of a thing, and then you refactor it out into a separate resource file. Blend does all the heavy lifting of figuring out how/what to add in the designer and then automatically carries that info into the dictionary while figuring out the wiring in between.

I think this is a great model. However, I wish Blend paid a bit more attention to one unfortunate fact: many of us are not used to such simplicity. My first attempt at using these features left me feeling frustrated. I created my resource dictionary, I opened it up, and saw this:


Ok, I guess this makes sense… I’ll use the Resources Panel to edit my resources. Unfortunately, the Resources Panel does not support adding new resources! With no further handy guidance, I just assumed that Blend has no real support for Resource Dictionary management and went back to editing XAML by hand.

I’m glad I did some more research and learned to use this great Blend feature. I do wish, however, that the Blend folks added one more link in the Resource chain and helped me transition away from the cumbersome designers of yesteryear and to this new model.


Unknown build error for WPF xmlns definition

Posted in Development with tags on January 20, 2011 by piotrp

I was recently working on a WPF application using the excellent WPF Toolkit when I ran across a strange build error in Visual Studio:

Unknown build error, ”clr-namespace:System.Windows.Controls.DataVisualization.Charting;  assembly=System.Windows.Controls.DataVisualization.Toolkit’ mapping URI is not valid.

The offending line of source code looks like this [edited for readability]:

  1. <Window
  2.    x:Class="Constructor.MainWindow"
  3.    xmlns ="…&quot;
  4.    xmlns:x="…&quot;
  5.    xmlns:y="clr-namespace:S.C;  assembly=S.W.C.DV.T"
  6.    xmlns:z="clr-namespace:S.C;  assembly=S.W.C.DV.T"
  7.    Title ="MainWindow" Height="350" Width="912"  
  8.    >

As you can see, I used white space to align blocks of text within the snippet. On lines 5 and 6 this was particularly useful because it allows for a  quick visual comparison of the assembly portion of these lines. Unfortunately, herein lies the problem.

A quick Bing search found the MSDN documentation for XAML Namespaces and Namespace Mapping for WPF XAML. This was an interesting read, explaining the meaning of attributes like x:Class as well as the purpose of the ever-present default xmlns and xmlns:x namespaces. In addition, the documentation alludes to the cause of my build error:

do not include any whitespace anywhere in the declaration.

My assumption that whitespace indenting within the xmlns attributes of the Windows tag was incorrect. Whitespace is interpreted as invalid input and causes compilation to fail.

I hope my post helps you resolve the cryptic Unknown build error!