如何将文本框的效果添加到样式 [英] how to add effect for text box to style

查看:42
本文介绍了如何将文本框的效果添加到样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向样式添加效果以重用它,但由于某种原因它不起作用...

I'm trying to add an effect to style in order to reuse it, but from some reason it doesnt work...

<Style x:Key="NumericTextBoxStyle" TargetType="{x:Type TextBox}">
    <Style.Resources>
        <TextBox.Effect x:Key="EffectStyle">
            <DropShadowEffect BlurRadius="56" 
                              Direction="392" 
                              Color="#FF872E2E" 
                              RenderingBias="Quality"/>
       </TextBox.Effect>
    </Style.Resources>

    <Setter Property="Height" Value="25"/>
    <Setter Property="Width" Value="120"/>
    <Setter Property="HorizontalAlignment" Value="Right"/>
    <Setter Property="VerticalAlignment" Value="Top"/>
    <Setter Property="TextAlignment" Value="Center"/>
</Style>

但是我如何添加样式部分?(还有我如何声明效果?)

but how do i add the style part ? (also how do i declare for the effect ?)

谢谢

推荐答案

尝试将 Effect 添加为 Setter

Try to add the Effect as a Setter instead

<Style x:Key="NumericTextBoxStyle" TargetType="{x:Type TextBox}">
    <Setter Property="Effect">
        <Setter.Value>
            <DropShadowEffect BlurRadius="56"
                              Direction="392"
                              Color="#FF872E2E"
                              RenderingBias="Quality"/>
        </Setter.Value>
    </Setter>
    <Setter Property="Height" Value="25"/>
    <Setter Property="Width" Value="120"/>
    <Setter Property="HorizontalAlignment" Value="Right"/>
    <Setter Property="VerticalAlignment" Value="Top"/>
    <Setter Property="TextAlignment" Value="Center"/>
</Style>

或者,如果您想将效果作为样式中的资源,您可以这样做

Or if you want to have the Effect as a Resource in the Style you can do it like this

<Style x:Key="NumericTextBoxStyle" TargetType="{x:Type TextBox}">
    <Style.Resources>
        <DropShadowEffect x:Key="dropShadowEffect"
                          BlurRadius="56"
                          Direction="392"
                          Color="#FF872E2E"
                          RenderingBias="Quality"/>
    </Style.Resources>
    <Setter Property="Effect" Value="{StaticResource dropShadowEffect}"/>
    <!--...-->
</Style>

这篇关于如何将文本框的效果添加到样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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