c# - Programatically removing Strikethrough TextDecoration from code behind in WPF -


i have problems achieving following behaviour in wpf desktop application:

i dynamically create textblocks code behind , insert them stackpanel. works far. when user moves mouse on textblock, strikthrough shall applied textblock, indicating item can deleted clicking on it. again, still works. when mouse leaves textblock, strikethrough shall removed, , here's exception thrown saying isfrozen must set false in order change textdecorationcollection object. wasn't able figure out how around this.

here's code:

private void handleaddedsecondarydxmouseenter(object sender, mouseeventargs e) {     textblock tbl = (textblock)sender;     tbl.textdecorations = textdecorations.strikethrough; }  private void handleaddedsecondarydxmouseleave(object sender, mouseeventargs e) {     textblock tbl = (textblock)sender;     tbl.textdecorations.remove(tbl.textdecorations[0]); } 

any appreciated.

thanks, bernd

you can set textdecorations null, clear strikethrough decoration textblock

private void handleaddedsecondarydxmouseleave(object sender, mouseeventargs e) {     textblock tbl = (textblock)sender;     tbl.textdecorations = null; } 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -