如何在wpf中创建以下样式?

时间:2016-03-29 09:51:55

标签: wpf xaml styles

如何设置按钮内容的样式,如下所示?对于样式1,使用文本块和运行似乎很容易,但样式2,我想知道如何实现这一点。 Style 1

Style 2

1 个答案:

答案 0 :(得分:1)

您可以使用offset

执行此操作
<TextBlock FontSize="72">
    <Run Foreground="Gray" Text="It" /><Run Text="e">
        <Run.Foreground>
            <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                <GradientStop Color="Gray" Offset="0"/>
                <GradientStop Color="Gray" Offset="0.5" />
                <GradientStop Color="Red" Offset="0.5" />
                <GradientStop Color="Red" Offset="1" />
            </LinearGradientBrush>
        </Run.Foreground>
    </Run><Run Text="m" Foreground="Red" /><Run Text=" 1">
        <Run.Foreground>
            <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                <GradientStop Color="Red" Offset="0"/>
                <GradientStop Color="Red" Offset="0.5" />
                <GradientStop Color="Gray" Offset="0.5" />
                <GradientStop Color="Gray" Offset="1" />
            </LinearGradientBrush>
        </Run.Foreground>
    </Run>
</TextBlock>

参考:Foreground colour of textblock based on position of part of the letter