RichTextBox for UWP | ComponentOne
Tutorials / Printing C1RichTextBox Contents / Step 1 of 4: Setting up the Application
In This Topic
    Step 1 of 4: Setting up the Application
    In This Topic

    In this step, you'll create a new Universal Windows application, add a C1RichTextBox control, and add the markup to create the C1RichTextBox control and a C1RichTextBoxMenu control.

    1. Select File | New | Project to open the New Project dialog box.
      1. Select Templates | Visual C# | Windows | Universal. From the templates list, select Blank App (Universal Windows).
      2. Enter a name for your application and click OK. A new application will open.

    2. In the Solution Explorer, right-click the References file and select Add Reference from the list. Browse to locate the following assembly references:
      • C1.UWP
      • C1.UWP.RichTextBox
      • C1.UWP.RichTextBox.Menu

    3. Double-click the MainPage.xaml file to open it.
    4. Add the following namespace declaration to the <Page> tag at the top of the page:
      XAML
      Copy Code
      xmlns:c1RTB="using:C1.Xaml.RichTextBox"
      

    5. Next, you'll add some Grid.Resources and RowDefinitions. The following markup should be placed between the <Grid> </Grid> tags:
      XAML
      Copy Code
      <Grid.Resources>
                  <DataTemplate x:Name="printTemplate">
                      <Grid Height="{Binding ViewManager.PresenterInfo.Height}" Width="{Binding ViewManager.PresenterInfo.Width}">
                          <c1RTB:C1RichTextPresenter Source="{Binding}" Margin="{Binding ViewManager.PresenterInfo.Padding}" />
                      </Grid>
                  </DataTemplate>
              </Grid.Resources>
              <Grid.RowDefinitions>
                  <RowDefinition Height="Auto"/>
                  <RowDefinition/>
              </Grid.RowDefinitions>
      

    6. Right below the closing </Grid.RowDefinitions> tag, add a general Button control. Edit the markup so that it resembles the following. You'll add a Name, the Content, and a Click event:
      XAML
      Copy Code
      <Button x:Name="btnPrint" Content="Print" HorizontalAlignment="Left" Click="btnPrint_Click" />
      

    7. Finally, add aC1RichTextBoxMenu control and a C1RichTextBox control by locating the controls in the Visual Studio ToolBox and double-clicking them. Edit the markup to resemble the following:
      XAML
      Copy Code
      <c1RTB:C1RichTextBoxMenu x:Name="rtbMenu" RichTextBox="{Binding ElementName=rtb}" Grid.Row="1" />
      <c1RTB:C1RichTextBox x:Name="rtb"  Grid.Row="1"
                                   FontFamily="Times New Roman"
                                   FontSize="20"
                                   ViewMode="Print"
                                   HorizontalContentAlignment="Center"
                                   Background="#EEEEEE"/>
      

    In this step, you set up a new Universal Windows application, added the appropriate references for the application, and added C1RichTextBox controls to the application. In the next step, you'll add the appropriate resource files and some application code.