Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set a property of a DropShadowEffect via a Trigger in a ControlTemplate?

I have a Button ControlTemplate and I'm trying to modify a DropShadowEffect on a Border by using a Trigger. Here is my Xaml:

<Button.Template>
  <ControlTemplate TargetType="Button">
    <Border x:Name="ButtonBorder" Margin="10" CornerRadius="5" Background="Gray">
      <Border.Effect>
        <DropShadowEffect ShadowDepth="5" x:Name="BorderEffect" />
      </Border.Effect>
      <ContentPresenter HorizontalAlignment="Center" />
    </Border>
    <ControlTemplate.Triggers>
      <Trigger Property="Button.IsMouseOver" Value="True">
        <Setter Property="Background" TargetName="ButtonBorder" Value="LightGray" />
      </Trigger>
      <Trigger Property="Button.IsPressed" Value="True">
        <Setter Property="Margin" TargetName="ButtonBorder" Value="13,13,7,7" />
        <!-- this is where I get the error -->
        <Setter Property="ShadowDepth" TargetName="BorderEffect" Value="2" />
      </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>
</Button.Template>

I get an error stating that the BorderEffect cannot be found.
I have also tried:

<Setter Property="Effect.ShadowDepth" TargetName="ButtonBorder" Value="2" />

But I also get an error telling me that the property ShadowDepth could not be found on the object of type Effect (because it's using the base class instead of DropShadowEffect)

How can I solve this?

like image 779
Julien Poulin Avatar asked Nov 17 '09 16:11

Julien Poulin


1 Answers

You can set the Effect as a whole in the setter.value

 <Setter Property="Margin" TargetName="ButtonBorder" Value="13,13,7,7" />
    <Setter Property="Effect" TargetName="ButtonBorder" >
      <Setter.Value>
         <DropShadowEffect ShadowDepth="2" />
      </Setter.Value>
    </Setter>
  </Trigger>
like image 59
Jobi Joy Avatar answered Oct 16 '22 01:10

Jobi Joy