We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to load PDF using Prism 7.0 dependency injection?

Install Prism.Unity.Forms package to your projects in the Visual Studio solution.

 

PCL/ .NET Standard

 

Open the App.xaml file and change the <Application> to <PrismApplication>.

 

XAML

 

Open App.xaml.cs file and change Application to PrimsApplication.

C#

 

Modify the constructor of the App class as follows..

C#

 

In the same App class, set the BindingContext of the MainPage to the PdfViewerViewModel class using the RegisterTypes method.

C#

 

Place the call to InitializeComponents method in OnInitilaized method. Also, set the MainPage property of the App.

C#

 

Include an interface to the portable project with name IFileHelperService. This interface defines the methods that fetch streams from the PDF files to be loaded.

C#

 

Add a ViewModel class to the project with name PdfViewerViewModel that implements the INotifyPropertyChanged interface. Define a property PdfStream of type MemoryStream in the class. The stream to be loaded into PdfViewer is read from the file location using IFileHelperService interface and set to the PdfStream property.

C#

 

Bind the InputFileStream property of the PdfViewer in XAML to the PdfStream property defined in the ViewModel class.

XAML

 

Android

Implement the IFileHelperService interface in Android.

C#

 

Define a static field of type FileHelperService in the MainActivity class.

C#

 

Include a new class to the Android project with name AndroidInitializer that implements the IPlatformInitializer interface. Register the static field defined in MainActivity class with the containerRegistry.

 

 

C#

 

Pass an instance of the AndroidInitializer class as a parameter to the constructor of App class in the LoadApplication method call in MainActivity.

C#

 

iOS

Implement the IFileHelperService interface in iOS platform.

C#

 

Define a static field of type FileHelperService in the AppDelegate file.

C#

 

Include a new class to the iOS project with name IOSInitializer, which implements the IPlatformInitializer interface. Register the static field defined in the AppDelegate file with contentRegistry.

C#

 

Pass an instance of the IOSInitializer class as a parameter to the constructor of App class in the call to LoadApplication in AppDelegate.

C#

 

UWP

Implement the IFileHelperService interface in UWP platform.

C#

 

Define a static field of type FileHelperService in the MainPage class of the UWP project.

C#

 

Add a class with name WindowsInitializer to the UWP project, which implements the IPlatformInitializer interface. Register the instance of the FileHelperService that has been created in the MainPage with contentRegistry.

C#

 

Pass an instance of the class WindowsInitializer as an argument to the constructor of the App class in the LoadApplication method call in MainPage.

 

C#

 

Sample link:

http://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfViewerDependencyInjection1045776787

 

 

Note:

Before running the sample, place the PDF document in the folder locations used in the FileHelperService class of the three platforms. Also, change the PDF file name to the name of the PDF you are using.

Article ID: Published Date: Last Revised Date: Platform: Control:
8916 07/06/2018 07/06/2018 Xamarin.Forms PdfViewer
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon