views:

192

answers:

2

I've not been able to find a whole lot on this anywhere. Let me start by saying I don't want to use the old Windows Form. I want to add a new WPF Window to my outlook 2007 addin project in visual studio 2008. The WPF Window template however does not show up. I was following this tutorial: http://msdn.microsoft.com/en-us/library/bb410039.aspx, which even had a picture of how you could add a new wpf window to your outlook 2007 addin. The only problem is that it is for visual studio 2005. Surely microsoft did not remove this ability from visual studio 2008. I must be doing something wrong.

Does anyone have any ideas or suggestions on where I can go from here?

I also cannot find a similar tutorial on msdn using visual studio 2008, that would be helpful as well.

+1  A: 

(Answer completely rewritten)

You are correct, VS 2008 no longer lists the 'WPF window' template in an add-in. Fortunately, it still lists the 'WPF User Control' template. Use it. This will add the necessary references to the project.

Then replace the contents of the generated XAML file (in my case, it was UserControl1.xaml) by what you have in Figure 5 (+ the end tag). Instead of declaring a UserControl, you now have a Window in the XAML. You also need to edit the generated C# file. Replace the class name (for me, it was UserControl1) by the name in the tutorial (Window2) and its constructor, too. Change the derivation from UserControl to Window. Here is the end result:

public partial class Window2 : Window {
    public Window2() {
        InitializeComponent();
    }

It is quite important that the namespace and class name in the .cs match the x:Class declaration in the XAML.

Now, follow what the tutorial says (not forgetting to adapt the path to the image file, otherwise it doesn't work. The original line in the tutorial is:

imageSource.UriSource = new Uri(@"C:\Fulvio\img\yast_suse_tour.png");

Set the path to an existing image on your hard drive.

And then it works!

I have to add that this tutorial was written before VS had a XAML designer. It is no longer needed to add controls by hand like the tutorial does. Add a user control, change it to a window and then use the toolbox and drag&drop controls, like you may be used to.

But as far as creating an outlook add-in is concerned, the tutorial is great.

Timores
I am a bit confused. My problem is I can't add the wpf form to the project. It doesn't show up in the templates when you do new item. It looks to me like the msdn article adds a wpf form not a windows one. I'm close to just giving up and adding a windows form, which does show up in the templates. It looks like a really helpfull tutorial. I have seen questions in various places asking the same thing, why does wpf window not show up in add new items. There are never any awnsers.
Anonymous Coward
You're right, I have read the article too quickly (the section creating the form is called 'Creating the Window Form', which I interpreted as 'Creating the WinForm') . I am trying the tutorial and I'll come back to you. Note that when adding an item to the project, the 'WPF user control' template is present.
Timores
Thanks for your help. I eventually started just looking for ways to add wpf forms to any kind of project. I found a work around which I posted as an answer. It did involve using that WPF user control, and just replacing everything with window. I was then able to add the code to show the window.
Anonymous Coward
I actualy found the awnser by reading http://www.i-think22.net/archives/2008/08/05/adding-wpf-windows-to-an-existing-windows-form-project/, but since you helped me out so much, and your answer is more complete than what I figured out. I have marked yours as the answer.
Anonymous Coward
Thanks, and the article is a good link that I didn't know of.
Timores
A: 

I really don't like this solution, but it works. I found http://www.i-think22.net/archives/2008/08/05/adding-wpf-windows-to-an-existing-windows-form-project/. That post talks about adding a wpf form to an existing windows form project. I just added the wpf user control, which was the only option it gave. I then renamed usercontrol to window. Updated the references and it works.

The only thing is, I shouldn't have to do that... I'm still hoping someone else comes up with something better.

Anonymous Coward