动画"本"和"其他"在WPF [英] Animating "this" and "other" in WPF
问题描述
考虑下列任何列表控制的DataTemplate:
Consider following DataTemplate in any List Control:
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
和动画如下:
<Window.Resources>
<Storyboard x:Key="animExpand">
<DoubleAnimation Storyboard.TargetProperty="Width" To="400" Duration="0:0:1" />
<DoubleAnimation Storyboard.TargetProperty="Height" To="400" Duration="0:0:1" />
</Storyboard>
<Storyboard x:Key="animCollapse">
<DoubleAnimation Storyboard.TargetProperty="Width" To="0" Duration="0:0:1" />
<DoubleAnimation Storyboard.TargetProperty="Height" To="0" Duration="0:0:1" />
</Storyboard>
</Window.Resources>
现在,我们希望:所有的TextBlocks的获得点击的时候,animExpand适用于它和所有的其他的TextBlock有一个animCollapse
Now we want: when any of TextBlocks get clicked, "animExpand" apply to it and all other TextBlock have a "animCollapse".
第一部分是简单(触发器会做),但问题是,如何让其他元素在这种情况下参加吗?
First part is straightforward (a Trigger would do it) but the question is how to make other elements take part in this scenario?
推荐答案
我想我会把一个布尔属性(IsExpanded或东西)在我的模型,然后创建一个datatrigger做基于价值的动画。当鼠标按下某个特定项目时,你不得不写的逻辑是,在该列表中的其他对象,则更新。
I think I would put an boolean property (IsExpanded or something) in my model and then create a datatrigger to do the animations based on that value. When a mousedown occurs on a particular item, you'd have to write the logic to updates that boolean in the other objects in the list.
这篇关于动画&QUOT;本&QUOT;和&QUOT;其他&QUOT;在WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!