RichTextBox for UWP | ComponentOne
Tutorials / Creating an AppBar Application / Step 3 of 5: Adding General Application Code
In This Topic
    Step 3 of 5: Adding General Application Code
    In This Topic

    In this step, you'll add code to create some of the AppBar items and to handle the C1RichTextBox control's events.

    1. Open MainPage.xaml again, and right-click the page. Select View Code from the context menu.
    2. Add the following using statements to the top of the page:
    C#
    Copy Code
    using C1.Xaml;
    using C1.Xaml.RichTextBox;
    using C1.Xaml.RichTextBox.Documents;
    using System.Reflection;
    using Windows.UI.Text;
    using Windows.UI;
    using Windows.UI.Popups;
    
    1. Directly below the InitializeComponent() method, add the InitMorePopup() method:
    C#
    Copy Code
    this.InitMorePopup();
    
    1. Next, you'll add the code that will update the C1RichTextBox control with eight C1 Tools:
    C#
    Copy Code
    btnBold.RichTextBox = rtb;
    btnItalic.RichTextBox = rtb;
    btnUnderline.RichTextBox = rtb;
    btnIncreaseFontSize.RichTextBox = rtb;
    btnDecreaseFontSize.RichTextBox = rtb;
    btnLeftAlign.RichTextBox = rtb;
    btnCenterAlign.RichTextBox = rtb;
    btnRightAlign.RichTextBox = rtb;
    
    1. Now, add the code that will load your content resource. Remember to insert your application name where the code says "YourApplicationName.Resources.simple.htm":
    C#
    Copy Code
    Assembly asm = typeof(MainPage).GetTypeInfo().Assembly;
    Stream stream = asm.GetManifestResourceStream("YourApplicationName.Resources.simple.htm");
    var html = new StreamReader(stream).ReadToEnd();
    rtb.Html = html;
    
    1. Last, add the event handler for the RequestNavigate event:
    C#
    Copy Code
    private async void rtb_RequestNavigate(object sender, RequestNavigateEventArgs e)
            {
                var md = new MessageDialog("The document is requesting to navigate to " + e.Hyperlink.NavigateUri, "Navigate");
    
                md.Commands.Add(new UICommand("OK", (UICommandInvokedHandler) =>
                {
                    Windows.System.Launcher.LaunchUriAsync(e.Hyperlink.NavigateUri);
                }));
    
                md.Commands.Add(new UICommand("Cancel", (UICommandInvokedHandler) =>
                {
                    rtb.Select(e.Hyperlink.ContentStart.TextOffset, e.Hyperlink.ContentRange.Text.Length);
                }));
    
                await md.ShowAsync();
    

    In this step, you added code to handle C1RichTextBox events and to create some of the C1 Tools used in the AppBar. In the next step, you'll add the code for the bottom AppBar.