How to make EntranceThemeTransition works on a Custom Panel & ItemsSource?

空扰寡人 提交于 2019-12-02 04:13:39

It is really a bug. The binding gets applied together or just after the animation. Because EntranceThemeTransition just happens once, it thinks that it already executed and disables it.

This is the workaround I'm currently using:

C#:

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 });
}


XAML:

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

Thanks Franklin Chen for the insight on MSDN forum about adding the items on code behind.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!