0

I am trying to create a WPF application that has a richtextbox which accepts dictations from the user as its input.

I want to use this code for the SpeechRecognized event for an an object of the SpeechRecognitionEngine class.

private void speechRecognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
  {
      e.Result.Text = rtb.Text; //rtb is an object of the RichTextBox class
  }

The problem is that there is no Text property for the RichTextBox class. Is there any way of fixing this? Thanks in advance

user3656168
  • 41
  • 2
  • 7

3 Answers3

0

RichTextBox contents can be set via Document property. You can find more details on MSDN

Here is an example from the link provided above. It creates a new document and a paragraph for it, then assigns the document to RichTextBox:

// Create a simple FlowDocument to serve as content.
FlowDocument flowDoc = new FlowDocument(new Paragraph(new Run("Simple FlowDocument")));
// Create an empty, default RichTextBox.
RichTextBox rtb = new RichTextBox();
// This call sets the contents of the RichTextBox to the specified FlowDocument.
rtb.Document = flowDoc;
// This call gets a FlowDocument representing the contents of the RichTextBox.
FlowDocument rtbContents = rtb.Document;
SoftwareFactor
  • 8,430
  • 3
  • 30
  • 34
0

Try this:

 private void speechRecognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
  {
       rtb.AppendText(e.Result.Text);
  }
Leo Chapiro
  • 13,678
  • 8
  • 61
  • 92
0

This is a well documented problem and there are many different solutions for it. You can find a large number of possible solutions in the answers to the RichTextBox (WPF) does not have string property “Text” question here on Stack Overflow.

However, my preferred method would be to declare a Text Attached Property for the RichTextBox class. Please see the Attached Properties Overview page on MSDN to find out more about Attached Properties. You can find out what code to use in your Text Attached Property for the RichTextBox class in the RichTextBox Text property where are you hiding? tutorial on C# Disciples website.

Community
  • 1
  • 1
Sheridan
  • 68,826
  • 24
  • 143
  • 183