开发者

ListboxItem Storyboard Animation

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, h开发者_JAVA技巧ow 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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜