Tuesday, December 22, 2009

Creating a WPF Outlook 2010 addin with VS2010 without writing one line of XAML

Beth Massi - Sharing the goodness that is VB - Build WPF Data Controls for Outlook Addins Easily with VS2010

“Last post I showed how to migrate our Northwind Outlook client to .NET 4 and Office 2010. This Outlook Add-in displays order history information in an adjoining form region so sales associates can see that data immediately when communicating with customers. When we originally built this with Visual Studio 2008, we used a WPF user control to display the data so that we could better match the look and feel of Outlook 2007. However we had to manually figure out the colors we needed and bind the data to the controls by writing XAML by hand.

Today I want to show how we can use drag & drop data binding and the new WPF designer in Visual Studio 2010 to quickly create this control without writing one line of XAML ourselves.

Displaying WPF Controls in Form Regions with ElementHost

Office clients by default work with Windows Forms controls. If you create a new Form Region you can add any Windows form control from the toolbox onto it. If you want to add WPF controls you simply add what’s called an ElementHost control which you find in the WPF Interoperability tab on your toolbox. This allows you to select from and host WPF User Controls in your project.

This is the same technique in VS2008 and VS2010. However, VS2010 makes it much easier to create the WPF User Control in the first place because you can now use the data sources window to design and data bind WPF controls. The WPF designer is also much easier to use. Let’s see how we can build a WPF control that displays Order information and have Visual Studio generate all the XAML we need automatically for us, and have it look good too.

image

…”

You had me a “without writing one line of XAML…” 

Also shown is how you can host WPF in a plugin host that only supports WinForm controls (say for example, Windows Live Writer ;)

4 comments:

divo said...

Hi Greg, I'm just curious: How do create the screenshots of complete web pages?

Greg said...

I use IEPro (aka IE7Pro), http://www.ie7pro.com/. It has a cool Capture Current Tab as Bitmap feature. (Works great in IE8 too)

I've also used the Fireshot http://screenshot-program.com/downloads.php which while works in both IE and FireFox, I've had some stability problems (but newer versions seem much better)

Both are free... ;)

Keith said...

The best screen capture utility I've seen is Jing. It's made my techsmith and allows you to select a portion of the screen the save as image or video. The cool part is that you can save it in the cloud then embed the image using the URL.

Greg said...

@Keith
Yeah, since my comment and since IE7Pro has been abandoned I've ponyed up the funds and bought TechSmith's SnagIt. SnagIt is now my official fav and I now use it all over the place.