Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add effect for text box to style

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 ?)

thanks

like image 595
Igal Avatar asked Mar 01 '11 16:03

Igal


People also ask

How do I shade a text box in Word?

Select the shape or text box. On the Drawing Tools Format tab, click Text Fill > More Fill Colors. In the Colors box, either click the color you want on the Standard tab, or mix your own color on the Custom tab. Custom colors and colors on the Standard tab aren't updated if you later change the document theme.

How do you insert an intense effect in Word?

On the Format tab, in the Shape Styles group, click Shape Effects, and select an option from the list. To add or change a built-in combination of effects, point to Preset, and then click the effect that you want. To customize the built-in effect, click 3-D Options, and then choose the options that you want.


2 Answers

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>
like image 164
Fredrik Hedblad Avatar answered Oct 04 '22 02:10

Fredrik Hedblad


You can also make your effect a global resource, in order to use it with other styles/controls:

<Grid>
    <Grid.Resources>
        <DropShadowEffect x:Key="dropShadowEffect" BlurRadius="56" 
                            Direction="392" 
                            Color="#FF872E2E" 
                            RenderingBias="Quality"/>

        <Style x:Key="NumericTextBoxStyle" TargetType="{x:Type TextBox}">
            <Setter Property="Effect" Value="{StaticResource dropShadowEffect}" />
            <Setter Property="Height" Value="25"/>
            <Setter Property="Width" Value="120"/>
        </Style>
    </Grid.Resources>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition />
    </Grid.RowDefinitions>

    <TextBox Style="{StaticResource NumericTextBoxStyle}" />
    <TextBox Style="{StaticResource NumericTextBoxStyle}" Grid.Row="1" />

    <ComboBox Effect="{StaticResource dropShadowEffect}" Grid.Row="2" />
</Grid>
like image 24
madd0 Avatar answered Oct 04 '22 04:10

madd0