Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...