MoXAML Power Toys
MoXAML Power Toys is a Visual Studio AddIn that’s designed to make your coding that bit more productive for WPF/Silverlight applications.
I started writing MoXAML, partly because I wanted to address some of the features that I needed to be productive in WPF, but also as a complementary product to Karl Shifflett’s wonderful XAML Power Toys. Karl’s stated aim is to produce a tool that quickly and efficiently enables you to write LOB applications in WPF and Silverlight. My aim is to produce a tool that allows you to code with the minimum of effort in Visual Studio.
Update – 6th September 2011:
I’ve been rewriting MoXAML for VS 2010. The version I’ve just uploaded is the installer only version, and is intended to be installed for evaluation purposes as the internal registration mechanism has completely been rewritten. What does this mean exactly? Well, it means that you can install it and it will work properly as it stands (I’ve chosen to only include a small subset of the MoXAML commands to prove the application architecture).
OK, so we know the internal architecture has been rewritten, but what does this mean exactly? Well, a feature of the original MoXAML that I was unhappy with was the fact that I had to add commands and then add hard references to them in the VS integration part. This meant that I had to rerelease a new version of the code whenever I changed it, and that’s a complete PITA. Wouldn’t it be better, I thought, if I could come up with a mechanism for simplifying this and use a plugin based architecture instead? Well, thanks to those really nice people at Microsoft, I have the wonderful MEF to play with, so with a little bit of interface jiggery-pokery I can add new commands without any real hard code work, and more importantly if you want to add your own commands it’s easy for you to do – just add a reference to MoXAML.Infrastructure, add a class that derives from CommandBase and add some minimal configuration into your class constructor. All you need to do is add a unique CommandName, the Caption you want to appear on the relevant menu and the ParentCommandBar you want to Add the menu item to.
Update – 13th September 2011:
One of my favourite parts of MoXAML is the Scrubber command. While I liked it, it never felt finished to me, so now I’ve taken the time to address what I saw as the shortcomings in the original version. First of all, the options dialog isn’t shown when you run Scrubber; it’s in a separate menu of it’s own – Scrubber options. Secondly, I wasn’t happy that you could only scrub the project, sometimes I just want to scrub the file I’m currently in. Scrubber is now available for both the solution and the individual file. The cool thing – it’s available in it’s own DLL, so we are demonstrating the plugin nature of MoXAML.
Update – 15th September 2011:
MoXAML is now fully open source. Rather than maintaining it on the blog, I’ve created a dedicated codeplex page available at http://moxaml.codeplex.com/. All source will be maintained there.
After downloading, you’ll need to change the extension from .doc to .zip. This is a requirement of WordPress.com
Visual Studio 2010 version
Installer – no source: MoXAML.PowerToys.zip
Visual Studio 2008 version
Installer – no source: MoXAML Power Toys_Setup
Source code: MoXAML Power Toys Source
So, what can you do with MoXAML?
BabelCode – currently available only in VS 2008
With BabelCode you can instantly convert your VB code into C# and vice versa, how cool is that. Simply run BabelCode on your source code and it’s instantly converted.
BabelCode menu in operation.
Here’s the converted output from a BabelCode run.
Extract user control – currently available only in VS 2008
There have been times when I’ve been working on a piece of XAML and I’ve thought, “That would be really handy if it was a control – I could use it in so many places.” Well, with this feature, you can extract XAML and create a user control from it.
Here I’ve highlighted the items that I want to convert into a user control.
At this point, we enter the name of the control we want to create.
And here’s the control – added into our solution.
Scrubber – available in both VS 2008 and 2010
Scrubber performs a “beautify” on your XAML items. It’s called from the Solution menu – just click on one of your source files, choose the Scrubber options and sit back as it works its magic on all of the XAML files in your solution.
Here’s a typical piece of XAML:
We choose Scrubber from the menu, and the scrubber dialog appears:
Here’s the same piece of code from above – after it’s been scrubbed:
Since originally posting Scrubber, a number of people have contacted me to tell me that there was a bug in the original Scrubber code where special characters in XML were being screwed up. Well, Scrubber has been updated to correct this bug – your special characters are now preserved.
Keyword search – currently available only in VS 2008
Highlight a word in the source and select Lookup keyword from the menu, and voila – a Google and Live search are performed based on the keyword (using the appropriate language type as well).
Menu in action
Commenting – available in both VS 2008 and 2010
Well, currently you can comment your XAML code and it works OK if you do it once, but if you then attempt to comment over the block again, you get some problems. The following picture shows what the problem actually is.
It doesn’t look too good does it? The first Power Toy, the Comment command behaves slightly differently:
As you can see, multiple comments and it continues to behave. So, that’s the Comment command – I hope you like it.
The sister command of the Comment command is the Uncomment command, and it works it’s way back up through the comment tree to uncomment the commands.
Notify properties – available in both VS 2008 and 2010
Automatic properties are great, but they don’t play nicely with two way data binding. Now it’s simple to convert an automatic property to use INotifyPropertyChanged. All you need to do is pick the property in the code window and select Notify Property (C# Only), and it will add the necessary plumbing.
Cunningly enough, it adds the Changed method if it’s not already present. ;->
Notify Property in action:
After the command:
The AppWizard – currently available only in VS 2008
This command allows you to add a status bar, toolbar and menu to your application.
Calling the AppWizard
The AppWizard brings up a dialog where you choose whether or not you want to see a toolbar, a menu or a statusbar. If you choose to add a toolbar or menu, you even get standard icons added into your project. The CommandBindings and App.Resources are set up for you, and the relevant user controls are added into your main window. The statusbar hooks up to the Caps Lock, Scroll Lock, Insert and Num Lock keys to reflect the state of them. It also adds in a date and time which updates every second. I love WPF.
Behind the scenes, some of the code injected into your application is C#, but being a nice chap I’ve added a converter in there which translates the C# to VB.NET before it gets added to your project if it detects that your project is VB.NET.
Dependency Properties – currently available only in VS 2008
One of the banes of my life, is typing in boilerplate code – and boy is there a lot of it with Dependency Properties. Well – that’s about to end. The Create Dependency Property command lets you create an ordinary DP or Attached DP (or readonly versions) with a minimum of effort. Better still, it provides method implementations for you as well – and it does this in both C# and VB.NET.
Selecting the menu (from inside the code editor window) brings up a dialog to enter the core information that you need to create the DP. When you enter the default value, you need to put it in “exactly” as you would if you entered it manually. This means that you must put quotes around it if that’s what is expected by the datatype.
The Create Dependency Property window
When you choose Create, the relevant code gets added into the class.
Add FieldModifier – available in VS 2008 and 2010
This command searches through your project for XAML files which have x:Name set without setting a FieldModifier. If it finds any entries like this, it adds the x:FieldModifier = “private” attribute. I’d like to thank Josh Smith for providing the inspiration for this command – please see this blog post for more information.
To use this command, right click in the Solution Explorer and choose MoXAML Power Toys > Add FieldModifier.
As always, keep your comments and requests coming in. No idea goes unconsidered.