带WPF窗口的Visual Studio 2008 Outlook 2007加载项 [英] Visual Studio 2008 Outlook 2007 AddIn with WPF Window

查看:107
本文介绍了带WPF窗口的Visual Studio 2008 Outlook 2007加载项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在任何地方都找不到很多东西.首先,我不想使用旧的Windows窗体.我想在Visual Studio 2008的Outlook 2007外接程序项目中添加一个新的WPF窗口.但是WPF窗口模板没有显示.我正在学习本教程: http://msdn.microsoft.com/zh- us/library/bb410039.aspx ,甚至还展示了如何在Outlook 2007插件中添加新的wpf窗口.唯一的问题是它是针对Visual Studio 2005的.微软肯定没有从Visual Studio 2008中删除此功能.我一定做错了.

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?

我也无法使用Visual Studio 2008在msdn上找到类似的教程,这也会有所帮助.

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

推荐答案

(答案已完全重写)

您是正确的,VS 2008不再在加载项中列出"WPF窗口"模板.幸运的是,它仍然列出了"WPF用户控件"模板.用它.这将为项目添加必要的引用.

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.

然后用图5(+结束标记)替换生成的XAML文件的内容(在我的情况下是UserControl1.xaml).现在,您无需声明UserControl,而是在XAML中具有一个Window.您还需要编辑生成的C#文件.将类名(对我来说,它是UserControl1)替换为教程(Window2)及其构造函数中的名称.将派生从UserControl更改为Window.这是最终结果:

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();
    }

.cs中的名称空间和类名称与XAML中的x:Class声明相匹配非常重要.

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.

然后它起作用了!

我必须补充一点,本教程是在VS具有XAML设计器之前编写的.不再需要像本教程一样手动添加控件.添加用户控件,将其更改为窗口,然后使用工具箱并拖放控件,就像您以前那样.

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.

但是就创建Outlook加载项而言,该教程很棒.

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

这篇关于带WPF窗口的Visual Studio 2008 Outlook 2007加载项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆