将Line Gradient应用于项目中的所有文本框 [英] Apply Line Gradient to All Textboxes in a project

查看:67
本文介绍了将Line Gradient应用于项目中的所有文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将线条渐变应用到所有文本框的背景中一个项目。 我知道您可以在app.xaml中添加XAML,但我不确定我需要添加哪些元素才能使其工作。

I would like to know how to apply a line gradient to the background of all the textboxes in a project.  I know you can add XAML in app.xaml but I am not sure what elements I need to add to it for it to work.

推荐答案

您好wegoodwin,

Hi wegoodwin,

您可以在App.xaml中添加样式,像这样:

You can add style in App.xaml, like this:

 <Application.Resources>
        <ResourceDictionary>

            <Style TargetType="TextBox">
                <Style.Triggers>
                    <Trigger Property="IsFocused" Value="True">
                        <Setter Property="Background">
                            <Setter.Value>
                                <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                    <GradientStop Color="Yellow" Offset="0.0" />
                                    <GradientStop Color="Red" Offset="0.25" />
                                    <GradientStop Color="Blue" Offset="0.75" />
                                    <GradientStop Color="LimeGreen" Offset="1.0" />
                                </LinearGradientBrush>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>

    </Application.Resources>

当聚焦在TextBox中时,您将看到线条渐变。您不需要在样式中使用x:key,它将为项目中的所有文本框应用行渐变。

when focused in TextBox, you will see the line gradient. You don't need to use x:key in style, it will apply line gradient for all textbox in your project.

最好的问候,

Cherry


这篇关于将Line Gradient应用于项目中的所有文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆