Freigeben über


Using WPF Custom Control Inside Word 2007 ActionsPane

Using WPF Control inside word 2007 is really simple today I'll walk you through the process.          

 

 

image 

 

1) Go to start ->Visual Studio 9.0->Microsoft Visual Studio codename Orcas.

2) select New project->Office->2007 and select Word Document and name it WPFControlforWord2007.

3) Add an Existing WPF Custom control library to the same solution.

4) Add the following References to WPFControlforWord2007

    1. PresentationCore
    2. PresentationFramework
    3. WindowsBase
    4. WindowsFormsIntigration
    5. CustomControlLibrary

5) Write following code to add the control in Action Pane

private

void ThisDocument_Startup(object sender, System.EventArgs e)

{

CustomControlLibrary.

RatingUserControl objwpfctr = new CustomControlLibrary.RatingUserControl();

ElementHost host = new ElementHost();

host.Height = 100;

host.Child = objwpfctr;

ActionsPane.Controls.Add(host);

}

Here it is we have Custom WPF control in Word 2007 Actionspane

image

Sample code is attached

WPFControlforWord2007.zip

Comments

  • Anonymous
    May 21, 2008
    HII tried your blog but I'm getting some error, can you please help me this?Unable to cast object of type 'WpfCustomControlLibrary1.CustomControl1' to type 'System.Windows.ResourceDictionary'.When i create the Windows Presentation Foundation (WPF) Custom Control Library project and add the same to my VSTO project and shown the WPF Custom Control in my actions pane. Using Visual Studio 2008ThanksJezzyjezzy.kiss@gmail.com