Have been trying without any sucess.
how to set default font for a dynamically created wpf richtextbox
please point me in right direction
Thank you
Peter
Have been trying without any sucess.
how to set default font for a dynamically created wpf richtextbox
please point me in right direction
Thank you
Peter
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Nikunj SatasiyaRank #302 · 8.3K reputationPosted Jul 11, 2024, 12:47 AM EDT
Hi Peter,
I wrote solution for you, please take refrence from my code. hope this will work for you.
using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Media; namespace RichTextBoxFontExample { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); CreateAndSetRichTextBox(); } private void CreateAndSetRichTextBox() { // Create a new RichTextBox RichTextBox richTextBox = new RichTextBox(); // Set default font properties richTextBox.FontFamily = new FontFamily("Arial"); richTextBox.FontSize = 14; richTextBox.FontWeight = FontWeights.Normal; richTextBox.FontStyle = FontStyles.Normal; // Optional: Set initial text with the default font richTextBox.Document.Blocks.Clear(); Paragraph paragraph = new Paragraph(); paragraph.Inlines.Add(new Run("This is the default text with the default font settings.")); richTextBox.Document.Blocks.Add(paragraph); // Add the RichTextBox to a container, e.g., a Grid MainGrid.Children.Add(richTextBox); } } }