Application creation

<< Click to Display Table of Contents >>

Navigation:  Gnostice Document Studio .NET > Getting Started > Document Viewing > Xamarin >

Application creation

 

Steps to create a basic Xamarin document viewer application for Android and iOS.

 

1

Open Visual Studio 2019 and create a new Mobile App (Xamarin.Forms) project.

 

xamarin_basic_1

2

Give the project a name (say XamarinDocumentViewer)

 

xamarin_basic_2

3

In the subsequent wizard dialog choose the Blank template and make sure both Android and iOS platforms are ticked.

 

xamarin_basic_3

 

After the project is created, use either the GUI or the Package Manager Console and install the Gnostice.DocumentStudio.Xamarin NuGet package to the common project. In this example it is the project titled XamarinDocumentViewer.

 

xamarin_basic_4

4

Add the following code snippet that creates and initializes the Xamarin Document Viewer Control to the file MainPage.xaml.cs of the common project (XamarinDocumentViewer). Note that the code snippet shows the entire MainPage class constructor.

 

  public MainPage()
  {
      InitializeComponent();
 
      // Get the embedded document that was want to display
      var assembly = IntrospectionExtensions.GetTypeInfo(

          typeof(MainPage)).Assembly;
      Stream stream = assembly.GetManifestResourceStream(
            assembly.GetName().Name + ".sample_document.docx");
      stream.Position = 0;
      MemoryStream memStream = new MemoryStream();
      stream.CopyTo(memStream);
 
      // Create the document viewer, load the document and 

      // add the viewer to the layout
      DocumentViewer viewer = new DocumentViewer();
      viewer.LoadDocument(memStream);
      Content = new StackLayout
      {
          VerticalOptions = LayoutOptions.FillAndExpand,
          HorizontalOptions = LayoutOptions.FillAndExpand,
          Children =
          {
              viewer
          }
      };
  }

 

 

xamarin_basic_6

5

Add a sample document to the common project and set it up as an embedded resource.

 

xamarin_basic_5

6

Build the project and run it on an emulator.

 

xamarin_basic_7