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
Post a Comment