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.micro开发者_如何学Gosoft.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.
(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.
精彩评论