![]() " PdfPath", typeof( string), typeof(PdfViewerHost), new PropertyMetadata(PdfPathPropert圜hanged)) Public static readonly DependencyProperty PdfPathProperty = DependencyProperty.Register( Create a new class called PdfViewerHost, and addĬopy Code public class PdfViewerHost : WindowsFormsHost The next step is to subclass WindowsFormsHost to wrap our custom Windows Forms Component and add a DependencyProperty so that our custom WPF element is easy to use with WPF DataBinding.įirst add a reference in the project to WindowsFormsIntegration assembly. The private method ChangeCurrentDisplayedPdf simply changes the current PDF displayed in the Viewer and sets the scroll position to be the top of the document.Īt this stage we have enough functionality in the Windows Forms component to allow it to be used from WPF. In the rest of the class we add a property “PdfFilePath” so that the current PDF that is showing can be changed as well as a method that allows the PDF to be printed showing the printer options dialog. In the constructor we tell the control to hide the toolbar and set the reader to use FitH (Fit Horizontal). Private string pdfFilePath public PdfViewer()ĪtViewScroll( " FitH", 0) ![]() This relationship is depicted on the diagram below:Ĭopy Code public partial class PdfViewer : UserControl To use Windows Forms controls in WPF they themselves must be hosted in the WindowsFormsHost element. To make an ActiveX control usable in WPF it must be hosted in a Windows Forms control. You may be wondering why this is necessary? WPF cannot directly use an ActiveX control. When you have done this you will need to create a Windows Forms User Control to host the Adobe PDF Reader. The first step is to create a new WPF application in Visual Studio. Step 1 Create a New WPF Application in Visual Studio For those without a paid licence for Visual Studio, Visual C# 2010 Express should be sufficient. This article is in the format of a tutorial- it is assumed you are using Visual Studio 2010 and Expression Blend 4 (or have the Expression Blend 4 SDK installed) as well Adobe PDF Reader. If you don’t understand the basics of MVVM, I’d suggest checking out some of the links in the external links section first. It is assumed you already know the benefits of using MVVM understand basic details such as the usage of INotifyPropert圜hanged and ICommand and the advantages of avoiding writing logic in the code behind (although sometimes code-behind is appropriate).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |