virtual techdays india │ 22-24 nov 2010 developing office biz application using wpf on windows 7...

16
virtual techdays INDIA 22-24 Nov 2010 Developing Office Biz Application using WPF on Windows 7 Sarang Datye Sr. Consultant, Microsoft Sridhar Poduri Consultant, Microsoft

Upload: helen-holt

Post on 29-Dec-2015

216 views

Category:

Documents


3 download

TRANSCRIPT

virtual techdaysINDIA │ 22-24 Nov 2010

Developing Office Biz Application using WPF on Windows 7Sarang Datye │ Sr. Consultant, MicrosoftSridhar Poduri │ Consultant, Microsoft

virtual techdays

Introduction Application – Level Add-ins VSTO 4 Framework How the Office app loads the Add-in Customizing the Office Ribbon Custom Task Panes in Office Using WPF Controls in Office Solutions

S E S S I O N A G E N D A

virtual techdays

Prerequisites

• Office 2007 SP2/Office 2010• Windows 7• .net framework 4• The Visual Studio 2010 Tools for Office

Runtime.

virtual techdays

Introduction• Visual Studio provides the following types of project templates for

Office development:– Document-level customizations. This type of solution is associated with a specific

document.– Application-level add-ins. This type of solution is associated with the application

itself.

• To decide which of these project types is best for your solution, think about whether you want your code to run only when a specific document is open, or whether you want the code to be available whenever the application is running.

• We will focus on Application-level add-in development in our session today.

virtual techdaysApplication-Level Add-Ins

• Application-level add-ins consist of an assembly that is associated with a Microsoft Office application.

• Visual Studio includes tools to help you create add-ins. Add-in projects include an automatically generated class that represents the add-in. This class provides properties and events you can use to access the object model of the host application and run code when the add-in is loaded and shut down.

virtual techdaysVSTO and .net framework

virtual techdaysHow the Office App loads the Add-in

virtual techdays

Customizing the Office Ribbon

• To add a Ribbon to a project– On the Project Menu, click Add New Item. – In the Add New Item dialog box, select Ribbon (Visual Designer) or Ribbon (XML). For more

information about these templates, see Ribbon Overview.– In the Name box, type a name for the Ribbon item.

• Click OK.• Handling Events and Setting Properties

– The Ribbon Designer enables you to set control properties at design time by using the Properties window. In addition, the Ribbon exposes a strongly typed object model that you can use to get and set the properties of Ribbon controls at run time.

– You can double-click any control on the designer to open an event handler for the control's default event. You can create event handlers for all other control events by using the Properties window.

– Ribbon events and properties are located in the Microsoft.Office.Tools.Ribbon namespace. The Ribbon (Visual Designer) item automatically adds a reference to this assembly in the project and inserts the appropriate using or Imports statement at the top of the Ribbon code file.

virtual techdays

DEMO: Customizing Ribbon in Office

virtual techdaysCustom Task-panes in Office

• Custom Task Panes Overview– Task panes are user interface panels that are typically docked to one side of a window in a Microsoft Office application. Custom task panes

give you a way to create your own task pane and provide users with a familiar interface to access your solution's features. For example, the interface can contain controls that run code to modify documents or display data from a data source.

• Benefits of Custom Task Panes• Custom task panes let you integrate your features into a familiar user interface. You can create a custom task pane quickly by using Visual Studio

tools.

– Familiar User Interface• Users of applications in the Microsoft Office system are already familiar with using task panes such as the Styles and Formatting task

pane in Word. Custom task panes behave like other task panes in the Microsoft Office system. Users can dock custom task panes to different sides of the application window, or they can drag custom task panes to any location in the window. You can create an add-in that displays multiple custom task panes at the same time, and users can control each task pane individually.

– Windows Forms Support• The user interface of a custom task pane that you create by using the Office development tools in Visual Studio is based on Windows

Forms controls. You can use the familiar Windows Forms Designer to design the user interface for a custom task pane. You can also use the data binding support in Windows Forms to bind a data source to controls on the task pane.

• Creating a Custom Task Pane• You can create a basic custom task pane in two steps:• Create a user interface for your custom task pane by adding Windows Forms controls to a UserControl object. • Instantiate the custom task pane by passing the user control to the CustomTaskPaneCollection object in your add-in. This collection

returns a new CustomTaskPane object that you can use to modify the appearance of the task pane and respond to user events.

virtual techdaysCustom Task Panes in Office

• You can add a custom task pane to the applications listed above by using an application-level add-in.

• To add a custom task pane to an application– Open or create an application-level project for one of the applications listed above.– On the Project menu, click Add User Control.– In the Add New Item dialog box, change the name of the new user control to MyUserControl, and then click

Add.– The user control opens in the designer.– Add one or more Windows Forms controls from the Toolbox to the user control.– Open the ThisAddIn.cs or ThisAddIn.vb code file.– Add code to the ThisAddIn class.

• private MyUserControl myUserControl1; • private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;

– Add the following code to the ThisAddIn_Startup event handler• myUserControl1 = new MyUserControl(); • myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl1, "My Task Pane"); • myCustomTaskPane.Visible = true;

virtual techdays

DEMO: Custom Task Panes in Office

virtual techdaysUsing WPF Controls in Office Solutions• Adding WPF Controls to Office Projects at Design Time

– You cannot add WPF controls directly to UI elements in Office solutions. Instead, add a User Control (Winforms) item to your project, and use it as the design surface for WPF controls. Then, add the WPF user control to a UI element in your project.

• To add WPF controls to an actions pane, custom task pane, or form region– Open a project to which you want to add a custom task pane, an actions pane, or a form region. – Add a User Control (Winforms) item to your project.– From the Toolbox, add WPF controls to the WPF user control design surface. – By default, when the WPF user control designer is open, the Toolbox contains only WPF controls.– Build the project.– Add an actions pane, form region, or custom task pane to your project:– For form regions, add an Outlook Form Region item to the project. – For actions panes, add an Actions Pane Control or User Control item to the project. – For custom task panes, add a User Control item to the project. – From the ProjectName WPF User Controls tab of the Toolbox, drag the WPF user control to the designer for the actions

pane, form region, or custom task pane.– Visual Studio automatically creates an ElementHost object that hosts the WPF user control on the UI element.– Rebuild the project.

virtual techdays

Using WPF – contd…

• Hosting WPF Controls by Using the ElementHost Class– Visual Studio provides features that help you use Windows Forms controls in

your Office solutions, but it does not provide similar features for WPF controls. For example, you can add Windows Forms controls to documents and worksheets at design time by dragging controls from the Toolbox, or at run time by using helper methods. However, these tools are not available for WPF controls.

– WPF controls use the ElementHost class as an integration layer between a Windows Forms control or form and the WPF controls. When you add WPF controls to your solution at design time, Visual Studio automatically generates an ElementHost object for you.

virtual techdays

DEMO: WPF Controls in Office

virtual techdays

[email protected][email protected]