tags:

views:

73

answers:

2

Hi,

I have a UserControl, in the Resources section I have code like

    <Style TargetType="{x:Type Viewbox}">

        <Style.Triggers>
            <Trigger Property="Viewbox.IsMouseOver" Value="True">
                <Setter Property="Viewbox.Effect" >
                    <Setter.Value>
                        <DropShadowEffect Color="DarkGray" Direction="45" BlurRadius="30"></DropShadowEffect>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

SO this works for the ViewBox that I have in this control,

but when I do

<Viewbox.Triggers>
        <Trigger Property="Viewbox.IsMouseOver" Value="True">
            <Setter Property="Viewbox.Effect" >
                <Setter.Value>
                    <DropShadowEffect></DropShadowEffect>
                </Setter.Value>
            </Setter>
        </Trigger>
    </Viewbox.Triggers>

within the View Box I get errors....

Is there a way to add local triggers to the ViewBox without using a Style?

+1  A: 

The Triggers collections of FrameworkElements vs Styles and Templates accept different types of triggers. For FrameworkElement.Triggers you can only use EventTrigger, commonly used to start animations. Style, ControlTemplate, and DataTemplate Triggers collections can use the more common Trigger and DataTrigger like you're using. It's an odd setup that's always sort of felt like an unfinished feature. You could change your code to use a Storyboard to animate properties on the DropShadowEffect from an EventTrigger or just use the Style approach.

John Bowen
A: 

From MSDN

The collection of triggers established on an element only supports EventTrigger, not property triggers (Trigger). If you require property triggers, you must place these within a style or template and then assign that style or template to the element either directly through the Style property, or indirectly through an implicit style reference.

Veer