【问题标题】:Animating "this" and "other" in WPF在 WPF 中为“this”和“other”设置动画
【发布时间】:2010-09-27 08:20:14
【问题描述】:

考虑在任何列表控件中遵循 DataTemplate:

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

现在我们想要:当任何一个 TextBlock 被点击时,“animExpand”应用到它并且所有 other TextBlock 都有一个“animCollapse”。

第一部分很简单(触发器可以做到),但问题是如何让 其他 元素参与到这个场景中?

【问题讨论】:

    标签: wpf binding


    【解决方案1】:

    我想我会在我的模型中放置一个布尔属性(IsExpanded 或其他东西),然后创建一个数据触发器来根据该值执行动画。当特定项目上发生鼠标按下时,您必须编写逻辑来更新列表中其他对象中的布尔值。

    【讨论】:

      猜你喜欢
      • 2013-08-27
      • 2015-10-11
      • 1970-01-01
      • 2023-03-03
      • 2014-01-09
      • 2022-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多