i tried do some content in FlowDocument to be highlighten by rectangle. like following code:
<FlowDocument>
<Paragraph>
<Span>
here is a span.
<Span.Background>
<VisualBrush>
<VisualBrush.Visual>
<Rectangle Fill="Gray" RadiusX="5" RadiusY="5" Width="100" Height="50"/>
</VisualBrush.Visual>
</VisualBrush>
</Span.Background>
</Span>
</Paragraph>
<FlowDocument>
i want to set rectangle's width and height to span. how can i get span's actual width and height which determined by span's content's length?
added:
it dosen't work. (it occured System.InvalidOperationException in design time)
<FlowDocument>
<Paragraph>
<Span>
Here is a span.
<Span.Background>
<VisualBrush>
<VisualBrush.Visual>
<Rectangle Fill="Gray" RadiusX="5" RadiusY="5" Height="50" Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Span}}, Path=Width}"/>
</VisualBrush.Visual>
</VisualBrush>
</Span.Background>
</Span>
</Paragraph>
</FlowDocument>