本文介绍了有条件的风格在WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个风格,使得的TextBlock 看起来像一个链接:

I've made a style that makes TextBlock look like a link:

<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://

推荐答案

试试这个

<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,否则返回假。我希望这会有所帮助。

In SomeConverter write the logic if text start with http//: then return true else return false. i hope this will help.

这篇关于有条件的风格在WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 19:44