RichTextBox for UWP | ComponentOne
Working with RichTextBox for UWP / Menus and Commands / Using the AppBar
In This Topic
    Using the AppBar
    In This Topic

    The C1.Xaml.RichTextBox.AppBar library includes built-in tools that you can use to create a simple command bar. The built-in tools support the following commands: Bold, Italic, Underline, Undo, Redo, Increase Font Size, Decrease Font Size, Center Align, Right Align, Left Align, and Justify. There is no visible application bar control; however, you can add the C1 Tools included in the assembly to the application bar.

    For a full example of implementing the AppBar assembly in your application, please see the Creating an AppBar Application tutorial. You can also see the AppBarDemo sample that was installed in the ComponentOne samples folder:

    C:\Users\YourUserName\Documents\ComponentOne Samples\WinRT XAML Phone\C1.Xaml.RichTextBox\CS\RichTextBoxSamples

    To use the C1 Tools in the AppBar assembly, your markup should resemble the following. Place it after the closing </Grid> tag:

    XAML
    Copy Code
    <Page.BottomAppBar>
     <AppBar x:Name="topAppBar" Padding="10,0,10,0" >
     </AppBar>
    </Page.TopAppBar>
    

    Note that the AppBar can be set to appear at the top of the page as well, using the following markup:

    XAML
    Copy Code
    <Page.TopAppBar>
     <AppBar x:Name="bottomAppBar" Padding="10,0,10,0" >
     </AppBar>
    </Page.BottomAppBar>
    

    The C1 Tools you wish to use will be placed within a StackPanel control between the <AppBar> </AppBar> tags:

    XAML
    Copy Code
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
       <RichTextBox:C1BoldTool x:Name="btnBold" Style="{StaticResource BoldAppBarButtonStyle}" />
       <RichTextBox:C1ItalicTool x:Name="btnItalic" Style="{StaticResource ItalicAppBarButtonStyle}" />
       <RichTextBox:C1UnderlineTool x:Name="btnUnderline" Style="{StaticResource UnderlineAppBarButtonStyle}" />
    </StackPanel>
    

    If you wish to use a set of general Button controls, you can do that as well:

    XAML
    Copy Code
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
       <Button x:Name="btnCopy" Style="{StaticResource CopyAppBarButtonStyle}" Click="btnCopy_Click"/>
       <Button x:Name="btnPaste" Style="{StaticResource PasteAppBarButtonStyle}" Click="btnPaste_Click"/>
       <Button x:Name="btnCut" Style="{StaticResource CutAppBarButtonStyle}" Click="btnCut_Click"/>
    </StackPanel>
    

    Since the general Button controls have click events, you'll have to add the following code to handle the click events:

    C#
    Copy Code
    #region Clipboard
            private void btnCopy_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
            {
                rtb.ClipboardCopy();
            }
            private void btnCut_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
            {
                if (rtb.IsReadOnly)
                    rtb.ClipboardCopy();
                else
                    rtb.ClipboardCut();
            }
            private void btnPaste_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
            {
                if (!rtb.IsReadOnly)
                {
                    rtb.ClipboardPaste();
                }
            }
    #endregion