开发者

Apply TextDecorations to a CollapsibleSection

开发者 https://www.devze.com 2023-04-09 02:48 出处:网络
I have CollapsibleSection objects that are dynamically being created in code.I would like to simply say:

I have CollapsibleSection objects that are dynamically being created in code. I would like to simply say:

CollapsibleSection section = new CollapsibleSection();
section.TextDecoration = TextDecorations.Strikethrough;

This is proving more difficult that I thought. Does anyone have some insight on a simple way to strikethrough the entire content of a collapsible section?


I'm missing something still. Here's what I have so far:

 public static readonly DependencyProperty TextDecorationProperty = 
   DependencyProperty.RegisterAttached("TextDecoration", typeof(TextDecoration), 
   typeof(CollapsibleSection)); 

In my method where I am creating my CollapsibleSection I have this:

CollapsibleSection cs = new CollapsibleSection(); 
if (flagIsTrue) { 
  section.SetValue(TextDecorationProperty, TextDecorations.Strikethrough); 
}

These CollapbsibleSection's are used to populate a FlowDocument.

I get this exception: 'System.Windows.TextDecorat开发者_高级运维ionCollection' is not a valid value of property 'TextDecoration'.

What am I doing wrong?


You can use an attached property. This can be done in Code or XAML

<Expander Header="test" TextBlock.TextDecorations="Strikethrough">
    <TextBlock>This is some random text</TextBlock>
</Expander>


I got the attached property to not throw an error by changing the parameter from typeof(TextDecoration) to typeof(TextDecorationCollection) but the property never seemed to actually attach to the UIElement so I bagged it and just ended up setting the properly at the Paragraph level.

Thank you for your help though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号