Silverlight / WPF - Bind Richtextbox Firstline to TextBlock.

Asked By Mag Garge on 06-Feb-12 11:19 PM
How can i bind Firstline of Richtextbox to a TextBlock?

Some thing like this:
<RichtextBox x:name="rtb" />
<TextBlock Text= {Binding ElementName=rtb, Path=Docoment.FirstBlock}

Thanks in advance.
D Company replied to Mag Garge on 06-Feb-12 11:35 PM
Hello Friend.

first you have to fetch the text than assign it to text text block like this

  Fcharind= richTextBox1.GetFirstCharIndexOfCurrentLine();

int  firstline= richTextBox1.GetLineFromCharIndex(Fcharind);

string currentlinetext = richTextBox1.Lines[firstline];

richTextBox1.Select(firstcharindex, currentlinetext.Length);

//now assign here to Textblock

textBlock.Text =richTextBox1.Text;

Hope it helps!!
DL M replied to Mag Garge on 07-Feb-12 12:01 AM

TextBlock is a FrameworkElement available in the System.Windows.Controls namespace. There is a property named “Text” where you have to enter the text string.Read More