Created
February 26, 2012 08:23
-
-
Save randyburden/1915136 to your computer and use it in GitHub Desktop.
Enabling Custom Key-Press Logic for an IsReadOnly WPF RichTextBox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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