WPF C# - Get inline formated bold Text from TextBlock -


i'm adding textblock elements border elements in stackpanel. i'm adding , formating text of textblock adding inlines.

when clicked, want formated text of textblock.here code.

public void addtext() {     textblock mytext = new textblock();     mytext.inlines.add(new bold(new run("hello ")));     mytext.inlines.add("world!");      border myborder = new border();     myborder.child = mytext;     myborder.mousedown += new mousebuttoneventhandler(border_clicked);      mystackpanel.children.add(myborder); }  private void border_clicked(object sender, mousebuttoneventargs e) {     //border senderbox = (border)sender;     //textblock sendertext = (textblock)senderbox.child;     //bold inline = (bold) sendertext.inlines.elementat(0);     // how output "hello "? } 

border_clicked should output "hello ". can see i'm able bolded text how can ouput it?

@helen, there way text textpointer using textrange. try code

void myborder_mousedown(object sender, mousebuttoneventargs e) {     var senderbox = (border)sender;     var sendertext = (textblock)senderbox.child;     var inline = (bold)sendertext.inlines.elementat(0);      var textrange = new textrange(inline.contentstart, inline.contentend);     console.writeline(textrange.text); } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -