Skip to content

Instantly share code, notes, and snippets.

@randyburden
Created February 26, 2012 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randyburden/1915136 to your computer and use it in GitHub Desktop.
Save randyburden/1915136 to your computer and use it in GitHub Desktop.
Enabling Custom Key-Press Logic for an IsReadOnly WPF RichTextBox
In your XAML:
-------------
<RichTextBox
Name="MyRichTextBox"
PreviewKeyDown="MyRichTextBox_PreviewKeyDown" />
In your C# Code-behind:
-----------------------
private void MyRichTextBox_PreviewKeyDown( object sender, KeyEventArgs e )
{
if ( e.Key == Key.PageDown || e.Key == Key.End )
{
MyRichTextBox.ScrollToEnd();
}
else if ( e.Key == Key.PageUp || e.Key == Key.Home )
{
MyRichTextBox.ScrollToHome();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment