gpt4 book ai didi

Silverlight 布局状态前加载 -> 后加载转换只是不工作

转载 作者:行者123 更新时间:2023-12-02 04:07:35 25 4
gpt4 key购买 nike

当项目添加到列表框中时,我正在尝试添加初始动画。
为此,我使用了由 itemcontainerstyle 中的混合生成的 Layoutstates:

<VisualStateGroup x:Name="LayoutStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.2"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="AfterLoaded"/>
<VisualState x:Name="BeforeLoaded">
<Storyboard>
<DoubleAnimation Duration="0" To="35" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
<DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
<VisualState x:Name="BeforeUnloaded">
<Storyboard>
<DoubleAnimation Duration="0" To="0.85" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
<DoubleAnimation Duration="0" To="0.85" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
<DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
</VisualStateGroup>

我的列表框如下所示:
<ListBox Grid.Row="1" ItemsSource="{Binding Days}" x:Name="Days"
HorizontalAlignment="Stretch"
SelectedItem="{Binding CurrentDay, Mode=TwoWay}"
ItemTemplate="{StaticResource TimeRecordByDayItemTemplate}"
ItemsPanel="{StaticResource ByMonthDaysItemsPanelTemplate}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemContainerStyle="{StaticResource DayListBoxItemStyle}" />

即使我只是一步一步地遵循channel9教程,我也没有得到任何动画!

这是我的状态管理器的第一个问题,我也遇到了数据触发器的问题,当满足某些条件时,它应该进入一个状态,有些工作,有些不工作,但我所有的绑定(bind)都是正确的!
此外,所有动画都可以在 Expression Blend 预览中工作。

我无法找出问题所在,我经常遇到这种情况,因为 Silverlight 和从最简单的示例中复制的动画在自己的环境中不起作用(请看这里 channel 9)...

谢谢你的帮助!

最佳答案

听起来您需要在加载完所有内容后一一添加项目。在您的 View 模型中似乎是一个简单的解决方案:

public class MyViewModel
{
private string[] _items;
private ObservableCollection<string> _itemCollection;

public MyViewModel()
{
// meets requirement of loading items in constructor
_items = { "Johnny", "Thommy", "Jay", "Wommy" };
}

public ObservableCollection<string> Items
{
get
{
if (_itemCollection == null)
{
_itemCollection = new ObservableCollection<string>();
Dispatcher.Invoke(() => LoadItems());
}
return _itemCollection;
}
}

private void LoadItems()
{
foreach (var item in _items)
{
ItemCollection.Add(item);
}
}
}

基本上,当 ListBox 设置绑定(bind)时,您会将项目添加到集合中。这应该在正确的时间加载项目,以便它们触发您的动画。

关于Silverlight 布局状态前加载 -> 后加载转换只是不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6862917/

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