locked
StoryBoard in a ResourceDictionary (no use of x:Name) RRS feed

  • Question

  • This is the simplified code:

    <ResourceDictionary
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Grid x:Key="myKey" Background="#F2F2F2">
            <StackPanel>
                <StackPanel.Triggers>
                    <EventTrigger RoutedEvent="StackPanel.MouseDown">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.Target="??"
    			     Storyboard.TargetProperty="Height"
                                 Duration="0:0:0.15" To="150">
                                </DoubleAnimation>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </StackPanel.Triggers>
                <Popup IsOpen="True" Height="0">
                    <SomeContent.../>
                </Popup>
            </StackPanel>
        </Grid>
    </ResourceDictionary>


    So I have a Resource dictionary, with a grid, a stackpanel in it, and a popup in the stackpanel. What I want to do is to make the popup stretch out when I click the stackpanel.

    So I put a MouseDown eventTrigger in the stackpanel, and target should be the popup.

    That's the problem, if it weren't the ResourceDictionary I would use TargetName, but you cannot use x:Name in a Resource Dictionary. How do I target the Popup?

    I hope I was clear.

    Thanks!
    Thursday, January 7, 2010 2:48 PM

Answers

  • Hi Janjko,

    You can use data binding to target the Popup. For example:

     <Grid x:Key="myKey" Background="#F2F2F2">
            <StackPanel>
                <StackPanel.Triggers>
                    <EventTrigger RoutedEvent="StackPanel.MouseDown">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.Target="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}, Path=Children[0]}"
            Storyboard.TargetProperty="Height"
                                 Duration="0:0:0.15" To="150">
                                </DoubleAnimation>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </StackPanel.Triggers>
                <Popup IsOpen="True" Height="0">
                    <SomeContent.../>
                </Popup>
            </StackPanel>
        </Grid>

    Hope this helps.
    If you have any question, please feel free to let me know.

    Sincerely,
    Linda Liu

    MSDN Subscriber Support in Forum 
    If you have any feedback on our support, please contact msdnmg@microsoft.com

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Adnet Friday, January 8, 2010 12:59 PM
    Friday, January 8, 2010 8:05 AM

All replies

  • Hi Janjko,

    You can use data binding to target the Popup. For example:

     <Grid x:Key="myKey" Background="#F2F2F2">
            <StackPanel>
                <StackPanel.Triggers>
                    <EventTrigger RoutedEvent="StackPanel.MouseDown">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.Target="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}, Path=Children[0]}"
            Storyboard.TargetProperty="Height"
                                 Duration="0:0:0.15" To="150">
                                </DoubleAnimation>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </StackPanel.Triggers>
                <Popup IsOpen="True" Height="0">
                    <SomeContent.../>
                </Popup>
            </StackPanel>
        </Grid>

    Hope this helps.
    If you have any question, please feel free to let me know.

    Sincerely,
    Linda Liu

    MSDN Subscriber Support in Forum 
    If you have any feedback on our support, please contact msdnmg@microsoft.com

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Adnet Friday, January 8, 2010 12:59 PM
    Friday, January 8, 2010 8:05 AM
  • Thank you! Works!
    Friday, January 8, 2010 1:00 PM