带有样式的WPF超链接中的文本换行

时间:2012-10-10 08:10:45

标签: wpf hyperlink underline

<Hyperlink Command="{Binding Path=Source1}">
    <TextBlock x:Name="DescriptionText" TextWrapping="Wrap">
        <TextBlock.Style>
            <Style>
                <Setter Property="TextBlock.Text" Value="Click here to set Source1"/>               
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=IsActive}" Value="False">
                        <Setter Property="TextBlock.Text" Value="{Binding Path=Source1Des, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </TextBlock.Style>
    </TextBlock>
</Hyperlink>

我想只修剪文字下划线。怎么做?

1 个答案:

答案 0 :(得分:1)

使用Run而不是Textblock

    <TextBlock TextWrapping="Wrap">
        <Hyperlink Command="{Binding Path=Source1}">
            <Run>
                <Run.Style>
                    <Style TargetType="Run">
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Text"  Value="My mouse is over" />
                            </Trigger> 
                        </Style.Triggers>
                        <Setter Property="Text"  Value="Click here to set Source1" />
                    </Style>
                </Run.Style>
            </Run>
        </Hyperlink>
    </TextBlock>

另见this stackoverflow thread