Reputation: 67135
I keep going around in circles on this data trigger so it is not working...
I have a button that has a border for a default dropshadow. However, I want to create a dep property to be used to toggle this. Yet, I never get to the point where the effect is being set.
<Style x:Key="RoundedButton" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ctrls:RoundedButton">
<Grid>
<Border>
<Border.Style>
<Style TargetType="ctrls:RoundedButton">
<Style.Triggers>
<Trigger Property="IsDropShadowVisible" Value="True">
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="1"/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
This is based off of a button, but is implemented as the custom user control...This is legacy code...
Upvotes: 1
Views: 1437
Reputation: 5262
What I have here works Did this in a new WPF window. No other code-behind than what you see here.
<Window.Resources>
<Style TargetType="{x:Type local:ShadowButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ShadowButton}">
<Button Name="Button"></Button>
<ControlTemplate.Triggers>
<Trigger Property="IsDropShadowVisible" Value="True">
<Setter TargetName="Button" Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="1"/>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<!-- snip code -->
<local:ShadowButton Height="10" Width="10" IsDropShadowVisible="true"/>
Code-behind:
public class ShadowButton : Button
{
public DependencyProperty IsDropShadowVisibleProperty =
DependencyProperty.Register("IsDropShadowVisible", typeof(Boolean), typeof(ShadowButton), new PropertyMetadata(false));
public Boolean IsDropShadowVisible
{
get { return (Boolean)GetValue(IsDropShadowVisibleProperty); }
set { SetValue(IsDropShadowVisibleProperty, value); }
}
}
Upvotes: 1