Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

storyboard HandoffBehavior? RSS

1 reply

Last post Jul 03, 2009 07:48 PM by elmore.adam

(0)
  • dmacdonald

    dmacdonald

    Member

    22 Points

    17 Posts

    storyboard HandoffBehavior?

    Jul 01, 2009 11:21 PM | LINK

    Hi, 

     I'm trying to animate the opacity of an element so that it smoothly fades in and out when the mouse enters or leaves it. This is very simple in WPF using the HandoffBehavior property. I'm it this manually for each animation in code-behind for now but its ugly. Is there a simple way in xaml?

     Thanks,

    Daniel

     

  • elmore.adam

    elmore.adam

    Member

    482 Points

    67 Posts

    Re: storyboard HandoffBehavior?

    Jul 03, 2009 07:48 PM | LINK

    Daniel, Silverlight has a superior way of handling these type of state animations through the VisualStateManager (in fact, WPF 4 will be following suite and implementing the VSM). Granted, there is a bit of initial work that will need to be done to give you the control that you desire; namely, you will need to override the control template of the particular element you wish to implement these animations on. However, it is a powerful way to accomplish this sort of thing at a control level.

    Examine the following ControlTemplate (targeted at a Button control), and see if this doesn't point you in the correct direction:

    <ControlTemplate
        TargetType="Button">
        <Grid
            x:Name="PART_RootElement">
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup
                    x:Name="CommonStates">
                    <VisualState
                        x:Name="Normal" />
                    <VisualState
                        x:Name="MouseOver">
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="TargetElementName"
                                Storyboard.TargetProperty="Opacity"
                                To=".5" />
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
    --
    Kind Regards

    Adam Elmore
    MCTS: WPF, WCF

    417.200.4261
    elmore.adam@gmail.com
    http://adamelmore.net/