2009-10-02 39 views
1

我有一个子类型ListBox,其依赖项属性设置为Storyboard。当所选项目发生更改时,我想在ListBox的每个项目上运行此Storyboard在多个目标上开始故事板

这怎么可能与一个单一的Storyboard实例?

回答

1

故事板可以键入并从多个触发器运行,并且只要设置正确,它就可以很好地工作。如果我正确理解你,你希望将故事板应用于每个单独的ListBoxItem。在这种情况下,为什么不制作一个风格,并根据该风格的触发器来触发故事板。

请原谅我的伪代码。

<Storyboard x:Key="MyEnterStoryboard"> 
    <!-- Do Enter Work --> 
</Storyboard> 

<Storyboard x:Key="MyExitStoryboard"> 
    <!-- Do Exit Work --> 
</Storyboard> 

<Style TargetType="{x:Type ListBoxItem}"> 
    <Style.Triggers> 
     <Trigger Property="SelectedItemChanging" Value="True"> 
      <Trigger.EnterActions> 
       <BeginStoryboard Storyboard="{StaticResource MyEnterStoryboard}"/> 
      </Trigger.EnterActions> 
      <Trigger.ExitActions> 
       <BeginStoryboard Storyboard="{StaticResource MyExitStoryboard}"/> 
      </Trigger.ExitActions> 
     </Trigger> 
    </Style.Triggers> 
</Style> 
+0

非常感谢,这是有道理的。但是这如何转化为Silverlight?据我了解,SL不支持触发器。 – 2009-10-03 08:08:52

+0

对不起理查德,看到了WPF标签,而不是silverlight标签。我做了一些研究,发现你可能会使用行为。另外,根据您使用的SL版本,您可能可以使用SOME触发器。 – erodewald 2009-10-03 18:07:15

1

WPF故事板有Clone method。 Silverlight没有这个,但认为我会发布它,以防有人在这篇文章中寻找WPF解决方案。