Why Setter Property is not applied on Hyperlink?

时光总嘲笑我的痴心妄想 提交于 2020-01-04 02:28:10

问题


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:


You should set OverridesDefaultStyle to true:

<RichTextBox OverridesDefaultStyle="True">

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



来源:https://stackoverflow.com/questions/18558424/why-setter-property-is-not-applied-on-hyperlink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!