Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Maybe not the neatest solution but the you can inherit from the RichTextBox and add some behavior</p> <p>Declare your own Font Properties so you can bind them later with a List of Fonts </p> <pre><code> public class CustomControl1 : RichTextBox { public static readonly DependencyProperty CurrentFontFamilyProperty = DependencyProperty.Register("CurrentFontFamily", typeof(FontFamily), typeof (CustomControl1), new FrameworkPropertyMetadata(new FontFamily("Tahoma"), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,new PropertyChangedCallback(OnCurrentFontChanged))); } </code></pre> <p>Override the OnTextInput. You can't subscribe to this event on the RichTextBox has built-in handling for the bubbling of KeyDown and KeyUp and between them the TextInput is generated</p> <pre><code> protected override void OnTextInput(TextCompositionEventArgs e) { if (fontchanged) { TextPointer tp = this.CaretPosition.GetInsertionPosition(LogicalDirection.Forward); Run r = new Run(e.Text, tp); r.FontFamily = CurrentFontFamily; r.Foreground = CurrentForeground; this.CaretPosition = r.ElementEnd; fontchanged = false; } else base.OnTextInput(e); } </code></pre> <p>if your CurrentFontProperty has changed get the caret position and create a new Run with the new Text Input and set the FontFamily = CurrentFontFamily. You could also change the whole word if the carret is over a word, this article might be interesting to spot the word <a href="http://blogs.msdn.com/prajakta/archive/2006/11/01/navigate-words-in-richtextbox.aspx" rel="nofollow noreferrer">Navigate Words in RichTextBox</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload