Reputation: 4053
I have a Listbox
that is declared with this:
<ListBox Height="694" HorizontalAlignment="Left" x:Name="listBox1"
ItemContainerStyle="{StaticResource ListBoxItemStyle1}" />
ListBoxItemStyle1
is a simple style to which I've added a Storyboard
. My question is, how can I play this storyboard when the user selects the item? I want the selectedListBoxItem
to animate but can't seem to access the Storyboard (called sb
) from the code-behind as the compiler claims it does not exist.
Upvotes: 0
Views: 577
Reputation: 16708
You can do this by putting an EventTrigger in your Style. Not knowing your specific XAML, here's a generalized example:
<Style ... >
<!--[etc...]-->
<Style.Triggers>
<EventTrigger RoutedEvent="Selected">
<BeginStoryboard>
<Storyboard ...
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
Upvotes: 2