Why Setter Property is not applied on Hyperlink?

225 Views Asked by At

I want to set (e.g.) FontSize for all Hyperlinks in my window. This is my MainWindow's XAML content:

<Window.Resources>
    <Style TargetType="{x:Type Hyperlink}">
        <EventSetter Event="Click" Handler="Hyperlink_OnClick"/>
        <Setter Property="FontSize" Value="30"></Setter>
    </Style>
</Window.Resources>
<Grid>
    <RichTextBox>
        <FlowDocument>
            <Paragraph>
                something
                <Hyperlink>
                    <Hyperlink.Inlines>
                    clickable
                    </Hyperlink.Inlines>
                </Hyperlink> ...
            </Paragraph>
        </FlowDocument>
    </RichTextBox>
</Grid>

If I add the style explicitly it works... (i.e. add x:Key="HyperlinkStyle" to the Style tag, and add Style="HyperlinkStyle" to the Hyperlink)

How can I set the style automatically to all Hyperlinks ?

Edit:

@keyboardP, @Anatoliy and @kmatyaszek - you're all right... Thanks to you all! I finally moved the Style tag to the <RichTextBox.Resources> property.

1

There are 1 best solutions below

0
On BEST ANSWER

You should set OverridesDefaultStyle to true:

<RichTextBox OverridesDefaultStyle="True">

or you can move Hyperlink style from Window resources to RichTextBox resources.