问题
I want to set (e.g.) FontSize
for all Hyperlink
s 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 Hyperlink
s ?
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