Andrej Tozon's blog

In the Attic


You've got mail: Windows Forms & WPF interop

One of my favorite samples when talking about WPF is showing a rotating 3D letter 'e' in a Windows Forms application. You know, something like those "you've got mail" computer messages, seen in many Hollywood movies. Windows Forms/WPF interoperability features make this kind of stunt very easy to pull off and this is the recipe to make in happen in 15 minutes...

First, you'll have to come up with some kind of 3D element, which you can import in WPF. I used electric rain's ZAM 3D tool, which has the ability to export 3D elements directly to XAML, which can be later picked up and additionally arranged with  Expression Blend, for example. It actually took me just a couple of minutes to create a 3D letter 'e' and import the scene into Blend.


Rotating the 3D element was done by animating ViewPort's camera by setting 5 progressive key frames of its Rotate Transform property.


We need to make the element reusable, so we'll transform it to a user control. Expression Blend 2 (currently still in CTP version) fortunately makes this task very easy by exposing the "Make Control" task (Tools | Make Control...)

OK, half done... We now have a user control with rotating 3D element and a WPF Window, simply displaying it.

The next step is adding a new Windows Form to the project. Save the project in Blend, switch over to Visual Studio (2008) and add a new Form. Visual Studio will make sure all necessary interop assemblies will be added to the project in this process.

With newly created form displayed in the designer area and open a Toolbox. Right at the top (or elsewhere, depending on your project's name), there should be your WPF user control, ready to drag onto the form. When doing so, Visual Studio will create your control, hosted in the ElementHost control (a Windows Forms control, which can host a WPF element). Set control's size to a desired value and you're done.


Download the sample project here.

Undeleting shift-deleted emails in Outlook

This one's for future reference...

It so happened that I accidentally "permanently" deleted some emails from Outlook... You know, a well-trained keyboard sequence routine - select some (spam) email, shift+delete, enter, and spam's gone. It turned out I happened to select all email in my Outlook and when I managed to stop the deleting, the last two months of email were gone.

This could easily be a tragedy, if I weren't keeping my email accounts with gmail/google apps. However, I do like keeping copies of my email on my desktop, so I wanted to get that two months of lost email back.

I knew that shift-deleting items in Outlook's list doesn't really remove the email's content from the data file [at least until the next Compact command], I just wasn't sure how to get it back. Googling for solution returned many (payable) products and services, assuring positive results, but somewhere down the road, I managed to land on Blake Handler's page, giving a simple solution. Apparently the utility, called Inbox Repair Tool, used for diagnosing and repairing corrupted Outlook's Personal Folders files (.pst), also resets the deleted flag in the repair process. You just have to find a way to corrupt the .pst file. Here's the quick rundown:

  1. Backup your Outlook.pst file [Inbox Repair Tool will do this for you as well]
  2. Edit Outlook.pst in some HEX editor
  3. Alter one or couple of bytes in the file (I changed the first byte and that worked for me)
  4. Run Inbox Repair Tool [ScanPST.exe, if using Office 2007, it's in [c:\]\Program Files\Microsoft Office\Office12\
  5. Start Outlook. Undeleted email should be back.

SLODUG is expanding

While SLODUG web site is waiting for its facelift, all Facebook users are kindly invited to join SLODUG group over there. And if you're not familiar with the Facebook yet - it's fun. There's all sorts of stuff going on, you can do craziest things possible, and all your friends are invited to participate. You can share and compare your movie taste, find a perfect date, even play your favorite ZX Spectrum game and beat your friend's high score. But beware, you might as well find yourself chased by zombies or bitten by a vampire. Curious place, it is.

And SLODUG is now part of it.

Tick, tock... Silverlight Challenge: one week left

Just a quick reminder: 1st European Silverlight Challenge is entering the finishing line. As announced, the competition ends next Monday, which still gives you plenty of time to polish your applications and give them some finishing touches. When ready, don't forget to submit your app on local competition site (click here for Slovenian site). Note: you'll have to register and log in first to submit your entry.

Starting today, Silverlight v1.0 is also available through Windows Update, as an optional update.

Wait, there's more... also available through Windows Update from today, are updates for all Expression products, including service packs.

Just keep 'em coming...

WPF tutorials

If you're starting your development with Windows Presentation Foundation, head over to, as they're running a great video tutorial series on WPF app development.

Another exhaustive tutorials on designing WPF applications with Expression Blend can be found on the Expression Blend and Design Blog.

And while visiting, you might as well check out recently released Syndicated Client Experiences Starter Kit & Reader SDK. Remember New York Times Reader? With the SCE starter kit you can build similar experience for delivering your own content to the reader. I have a pretty fixed idea for using this, all I have to do now is find some extra time to pursue it. Anyway, another useful implementation of the SDK is the MSDN Magazine Reader, which also comes with the full source code.

A tooth for a... mobile

Nokia 6210 is a good and durable phone. Indestructible, I would even say. At least for us, ordinary users. I've had one since 2000, used it constantly, carried it with me all over the world, backpacking or business, dropping it on the floor now and then, and yet never had any problems with it.

In the end, I lost it to a nearly 12-months old, gaining her first 4 teeth (all at once!). The temptation was too strong and once in the mouth, the phone was immediately flooded with young saliva and its functions started to fail. Additional hard-drops to the floor probably helped too. It still works though, but since it lost its ability to connect to the network, it's kind of useless now.

It's amazing how real phones attract children. We've had a couple of toy mobile replicas and she barely looked at them. But seeing a real phone (preferably in action), she goes berserk...

I'll be getting a new mobile now...

About time... :)

The main contenders were IPhone or one from the HTC range... I don't know, I might also just choose something simple and cheap. You know... for making calls.

And happy birthday to you, Amber, you're 1 today.

Source Code for .NET Framework Libraries is available

It was announced with the release of Visual Studio 2008, now it's here - follow this thorough step-by-step instructions to enable this new feature; the setup involves a hotfix and some settings tweaking. The last thing to do is agree with the license, and  you'll be able to step through .NET Framework's source code. Cool...

Check also Daniel Moth's video - here.

Let Silverlight shine on YOU!

Join developers all around Europe in the ultimate Silverlight Challenge. Yes, the 1st European Silverlight Challenge is on and Slovenia is one of the many countries participating. For more information  head over to Slovenian and European competition site, read the official rules and start your Visual Studio. Also, feel free to discuss the Challenge and Silverlight on SLODUG's forums.

1st European Silverlight Challenge ends on January 28th, 2008. The spotlight is on you!

Gradient eyedropper in Expression Blend

Gradient eyedropper proved to be one of the fun features for presenting Windows Presentation Foundation/Expression Blend. While fun for presenting, its ability to capture the color spectrum of the mouse-crossed area is useful in real-time designing too.

Try this for example... Start up your Blend, create a new project and put a rectangle on a window. Select Gradient brush for rectangle's Fill property and click-select the Gradient eyedropper tool (next to the gradient/color selector):

Gradient eyedropper

With eyedropper selected, drag a mouse, holding the left button, vertically across the rainbow color scale (part of the color selector). And here comes the rainbow rectangle...

Rainbow rectangle

You can color swipe any area of the screen, as long as your eyedropper cursor stays inside Blend's main window. This is somehow different to using the "regular" Color eyedropper tools, which allows you to capture even colors outside Blend's bounds.

Now go color your life ;)

On a side note: Expression Blend 2 December Preview is out.

"Call me 2.0... Silverlight 2.0"

Right... no more "Mister 1.1", no more Alpha - Silverlight 2.0 Beta is expected in Q1 2008 (@Mix?), bringing a rich set of controls (including DataGrid!), higher level of WPF UI framework, more connectivity options and richer BCL support. This Beta is expected to include a Go-Live license.

Read the full announcement on ScottGu's blog.

While on a subject, Silverlight 1.1 Tools Alpha for Visual Studio 2008 [RTM] were released a couple of days ago.