我制作的风格让TextBlock
看起来像一个链接:
<Style x:Key="linkStyle" TargetType="TextBlock">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="TextDecorations" Value="Underline" />
</Trigger>
</Style.Triggers>
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Foreground" Value="Blue" />
<EventSetter Event="MouseLeftButtonDown" Handler="navigateLink" />
</Style>
仅当TextBlock.Text
以 http:// 开头时如何应用?
答案 0 :(得分:14)
试试这个
<Style x:Key="linkStyleConditional" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}" Value="True"/>
<Condition Binding="{Binding Path=Text, Converter={StaticResource SomeConverter}}" Value="True"/>
</MultiDataTrigger.Conditions>
<Setter Property="Foreground" Value="Orange" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
在SomeConverter中写入逻辑,如果文本以http //开头,则返回true,否则返回false。我希望这会有所帮助。