前:
1 <DockPanel Margin="10"> 2 <TextBox SelectionChanged="TextBox_SelectionChanged" DockPanel.Dock="Top" /> 3 <TextBox Name="txtStatus" AcceptsReturn="True" TextWrapping="Wrap" IsReadOnly="True" /> 4 5 </DockPanel>
后:
1 private void TextBox_SelectionChanged(object sender, RoutedEventArgs e) 2 { 3 TextBox textBox = sender as TextBox; 4 txtStatus.Text = "Selection starts at character #" + textBox.SelectionStart + Environment.NewLine; 5 txtStatus.Text += "Selection is " + textBox.SelectionLength + " character(s) long" + Environment.NewLine; 6 txtStatus.Text += "Selected text: '" + textBox.SelectedText + "'"; 7 }