gpt4 book ai didi

WPF动画扩展收缩高度

转载 作者:行者123 更新时间:2023-12-01 05:46:50 25 4
gpt4 key购买 nike

我想在图像上有一个触发器,它通过动画其高度属性来扩展和收缩 ItemsSource。

我有一个绑定(bind)到 ObservableCollection 的通用 ItemsSource,所以我不知道这个控件的总高度。

单击图像后,它应该更改其图像源字形以显示 itemssource 已扩展。一旦再次单击它,ItemsSource 应该开始从其当前高度收缩回 0 - 因为第一个动画可能没有完成。

目前我有以下图像触发器:

<Image Name="ExpandImage" Source="ArrowDown.png">
<Image.Triggers>
<EventTrigger RoutedEvent="Image.MouseLeftButtonDown">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height"
Storyboard.TargetName="myItemsControl"
From="0" To="300" Duration="0:0:2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Image.Triggers>
</Image>

这很难看,因为它动画到一个固定的高度 - 我需要它动画到 ItemsControl 的总(未知高度)。此外,它仅支持单向(扩展)动画。

我的 ItemsControl 很简单:
 <ItemsControl Name="myItemsControl" 
ItemsSource="{Binding Items}" Height="0" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<c:CustomUserControl/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

最佳答案

您可以使用...以及 ActualHeight 属性获取 Items Control 的实际高度。问题是它不是依赖属性。但是,您可以使用像 Kent Boogaart 在 this answer 中所做的附加行为来绑定(bind)它。 .

那应该让您绑定(bind)到实际高度。我会留给你写附加的行为。 :)

关于WPF动画扩展收缩高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1276860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com