C# 如何使入口在自定义面板上使用MeTransition&;物品来源?
我无法让MeTransition作为ItemsPanelTemplate在自定义面板上工作。见: 最简单的代码隐藏:C# 如何使入口在自定义面板上使用MeTransition&;物品来源?,c#,xaml,windows-phone,winrt-xaml,windows-10,C#,Xaml,Windows Phone,Winrt Xaml,Windows 10,我无法让MeTransition作为ItemsPanelTemplate在自定义面板上工作。见: 最简单的代码隐藏: public List<int> MyListExample = new List<int>() {0, 1, 2, 3, 4, 5}; public List MyListExample=new List(){0,1,2,3,4,5}; 最简单的XAML: <ListView Width="120" ItemsSource="{x:Bind M
public List<int> MyListExample = new List<int>() {0, 1, 2, 3, 4, 5};
public List MyListExample=new List(){0,1,2,3,4,5};
最简单的XAML:
<ListView Width="120" ItemsSource="{x:Bind MyListExample}">
<ListView.ItemContainerTransitions>
<TransitionCollection>
<EntranceThemeTransition FromVerticalOffset="200" IsStaggeringEnabled="True"/>
</TransitionCollection>
</ListView.ItemContainerTransitions>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<!--EntranceThemeTransition WORKS-->
<ItemsWrapGrid/>
<!--EntranceThemeTransition does NOT work-->
<!--<StackPanel/>-->
<!--EntranceThemeTransition does NOT work. goal: make this work-->
<!--<local:FluidPanel/>-->
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
你知道如何制作动画吗
PS:我在加载的事件上放了一个Debug.WriteLine,它被调用了两次,我不知道为什么。这可能会导致问题,因为此动画仅触发一次。可能是在添加ItemsSource之前触发的
PS2:它只在使用ItemsSource时发生。如果我直接在ListView XAML上添加元素,它会显示动画
(同时打开)这确实是一个bug。绑定将一起应用,或仅在动画之后应用。因为eTransfion只发生一次,所以它认为它已经执行并禁用了它 这是我目前正在使用的解决方法: C#:
public observetecollection items{get;set;}=new observetecollection(){0,1,2,3,4,5,6,7,8,9};
已加载私有异步void MyListView_(对象发送方,路由目标)
{
foreach(项目中的var项目)
MyListView.Items.Add(项目);
等待任务。延迟(1000);//等待动画
MyListView.SetBinding(ItemsControl.ItemsSourceProperty,new Binding(){Source=this,Path=new PropertyPath(“items”),Mode=BindingMode.TwoWay});
}
XAML:
感谢Franklin Chen提供有关添加代码隐藏项的见解
public ObservableCollection<int> items { get; set; } = new ObservableCollection<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
private async void MyListView_Loaded(object sender, RoutedEventArgs e)
{
foreach (var item in items)
MyListView.Items.Add(item);
await Task.Delay(1000); //wait for animation
MyListView.SetBinding(ItemsControl.ItemsSourceProperty, new Binding() { Source = this, Path = new PropertyPath("items"), Mode = BindingMode.TwoWay });
}
<ListView x:Name="MyListView" Loaded="MyListView_Loaded">
<ListView.ItemContainerTransitions>
<TransitionCollection>
<EntranceThemeTransition FromHorizontalOffset="0" FromVerticalOffset="2000" IsStaggeringEnabled="True"/>
</TransitionCollection>
</ListView.ItemContainerTransitions>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>