Visual Studio 2008 Outlook 2007 AddIn with WPF Window

99封情书 提交于 2019-12-06 04:59:30

(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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!