2
votes

I can't seem to find how to add a drop shadow to a hyperlink in a flow document. Since HyperLink is not a UIElement it has no Effect property (all my googling led me to DropShadowEffect). It does have a TextEffects collection but I can't seem to figure out how to create a drop shadow with that. Ultimately what I would like to do is add a dropshadow to the background brush not to the text itself.

My requirement is pretty vague, I just have to make the focus appearance look better (i.e. tab focus and keyboard focus, not mouse over), and I thought a light drop shadow would do the trick, but I'm open to other suggestions.

(I don't have enough rep to upload a screenshot grr so here's a simulation)

There is a HyperLink here

I would like to add a drop shadow around the gray part (light blue in my app) not the text (as mentioned before).

1

1 Answers

2
votes

I am pretty sure you can't do this on a per-inline basis. The way WPF provides effects is it applies them wholesale to a single object in the visual tree. Content elements like a Hyperlink are all combined into a single visual element in their parent (the FlowDocumentReader or comparable).

FlowDocument controls do have the ability to host child visual elements using the BlockUIContainer block content element, or InlineUIContainer inline content element. You can use this to apply a DropShadow to a single Hyperlink like so:

<FlowDocument>
        <Paragraph>
            <Run Text="This is a" />
            <InlineUIContainer>
                <TextBlock Background="#FFCDCDCD">
                    <TextBlock.Effect>
                        <DropShadowEffect ShadowDepth="3" Color="#FFC9C9C9" />
                    </TextBlock.Effect>
                    <Hyperlink><Run Text="hyperlink" /></Hyperlink>
                </TextBlock>
            </InlineUIContainer>
        </Paragraph>
</FlowDocument>