UWP - TextBox SelectionChanged event example

MainPage.xaml

<Page
    x:Class="UniversalAppTutorials.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:UniversalAppTutorials"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    >
    <StackPanel Padding="50" Background="AliceBlue">
        <TextBox
            x:Name="TextBox1"
            PlaceholderText="Input some text here"
            Header="TextBox"
            Margin="5"
            MaxHeight="125"
            Height="100"
            AcceptsReturn="True"
            TextWrapping="Wrap"
            ScrollViewer.VerticalScrollBarVisibility="Auto"
            SelectionChanged="TextBox1_SelectionChanged"
            SelectionHighlightColor="Crimson"
            />
        <TextBlock
            x:Name="TextBlock1"
            FontFamily="MV Boli"
            FontSize="30"
            Foreground="DodgerBlue"
            TextWrapping="Wrap"
            Margin="5"
            />
    </StackPanel>
</Page>
MainPage.xaml.cs

using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml;


namespace UniversalAppTutorials
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        /*
            TextBox.SelectionChanged event
                Occurs when the text selection has changed.
        */

        private void TextBox1_SelectionChanged(object sender, RoutedEventArgs e)
        {
            // Cast sender as a TextBox
            TextBox textBox = sender as TextBox;

            if (textBox.SelectedText.Length > 0)
            {
                // Get the TextBox selected text and display it on TextBlock
                TextBlock1.Text = "You selected:\n" + textBox.SelectedText;
            }
            else {
                TextBlock1.Text = "";
            }
        }
    }
}