I have problems achieving the following behaviour in my WPF desktop application:
I dynamically create TextBlocks from code behind and insert them into a StackPanel. This works so far. When the user moves the mouse over the TextBlock, a Strikthrough shall be applied to the textblock, indicating that the item can be deleted by clicking on it. Again, this still works. When the mouse leaves the textblock, the strikethrough shall be removed, and here's where the exception is thrown saying that IsFrozen must be set to false in order to change the TextDecorationCollection object. I wasn't able to figure out how to get around this.
Here's my 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 help would be greatly appreciated.
Thanks, Bernd
null
,tbl.TextDecorations = null;