ReportViewer for WPF and Silverlight | ComponentOne
C1ReportViewer Quick Start / Step 2 of 3: Adding Content to the C1ReportViewer Control
In This Topic
    Step 2 of 3: Adding Content to the C1ReportViewer Control
    In This Topic

    In the previous step you created a WPF application and added the C1ReportViewer control to your project. In this step you'll add PDF content to the C1ReportViewer control. Note that in this step you will add a PDF file that is included with the WPF Edition samples, which are by default installed in the Documents or MyDocuments folder in the Documents\ComponentOne Samples\WPF or Documents\ComponentOne Samples\Silverlight directory. If you choose, you can instead use another PDF file and adapt the steps. To customize your project and add a PDF file to the C1ReportViewer control in your application, complete the following steps:

    1. Navigate to the Solution Explorer, right-click the project name, and select Add │ Existing Item.
    2. In the Add Existing Item dialog box, locate the C1XapOptimizer.pdf file included in the ControlExplorer sample. In the file type drop-down box, you may need to choose All Files to view the PDF file. Note that if you choose, you can instead pick another PDF file to use.
    3. In the Solution Explorer, click the PDF file you just added to the application. In the Properties window, set its BuildAction property to Resource and confirm that the Copy to Output Directory item is set to Do not Copy.
    4. Switch to Code view by right-clicking the page and selecting View Code. In the next steps you'll add XAML markup to your application to add content to the drop-down box.
    5. Add the following imports statement at the top of the page:

      Visual Basic
      Copy Code
      Imports C1.WPF.ReportViewer
      

       

      C#
      Copy Code
      using C1.WPF.ReportViewer;
      
    6. Add the following code to the main class:
      Visual Basic
      Copy Code
      Public Sub New()
          InitializeComponent()
          Dim resource = Application.GetResourceStream(New Uri("QuickStart;component/C1XapOptimizer.pdf", UriKind.Relative))
      Me.C1ReportViewer1.LoadDocument(resource.Stream)
      End Sub
      

       

      C#
      Copy Code
      public MainPage()
      {
          InitializeComponent();
          var resource = Application.GetResourceStream(new Uri("QuickStart;component/C1XapOptimizer.pdf", UriKind.Relative));
          this.C1ReportViewer1.LoadDocument(resource.Stream);
      }
      

    This code adds a stream and loads the stream into the C1ReportViewer control. Note that if you named the application differently, you will need to replace "QuickStart" with the name of your project. If you added a different PDF file, replace "C1XapOptimizer.pdf " with the name of your file.

    If you run the application now, it will appear in the content window within the C1ReportViewer control:

     

     

    In this step you added content to the C1ReportViewer control. In the next step you'll view some of the run-time interactions possible in the control.