0

Can a storyboard be placed in a resource file such as styles.xaml? I have a toolbar that will be reused across many pages. I have this working now with a page level resource:

 <navigation:Page.Resources>
        <Storyboard x:Name="sbToolbarInitialization">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
                                           Storyboard.TargetName="Toolbar">
                <EasingDoubleKeyFrame KeyTime="0"
                                      Value="46" />
                <EasingDoubleKeyFrame KeyTime="0:0:1"
                                      Value="0">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <BackEase EasingMode="EaseOut" />
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </navigation:Page.Resources>

Which the border control uses:

<Border x:Name="Toolbar"
                Style="{StaticResource ToolbarBorderStyle}">
            <Border.RenderTransform>
                <CompositeTransform />
            </Border.RenderTransform>
            <i:Interaction.Triggers>
                <i:EventTrigger>
                    <ei:ControlStoryboardAction Storyboard="{StaticResource sbToolbarInitialization}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
 </Border>

Since I am already using the style.xaml file to place formatting for the border I would like to also store the storyboard there. Is this possible?

Emond
  • 50,210
  • 11
  • 84
  • 115
Dan
  • 77
  • 1
  • 5

1 Answers1

0

I've done something similar, storing the Storyboard in my App.xaml file and using across my entire application. One way to access it in your code-behind or view-model is as such:

public Storyboard MyStoryBoard = Application.Current.Resources["MyStoryBoard "] as Storyboard;

You could then bind that storyboard property to your view declaratively.

KodeKreachor
  • 8,852
  • 10
  • 47
  • 64
  • Thanks for the suggestion. I will give that a try. Are most just keeping this kind of stuff at the page level and duplicating as necessary? – Dan Feb 27 '12 at 18:51
  • We normally do yes, until we see a pattern develop where we can reuse the storyboard, then we'll pull it out into a more globally accessible mechanism. If it's specific to your view then I'd recommend keeping it local. – KodeKreachor Feb 27 '12 at 20:02