开发者

Stackpanel add item animation

开发者 https://www.devze.com 2022-12-20 13:10 出处:网络
I\'ve been struggling a while with marquee-style image scrolling control. At a moment, I stuck up with templated ItemsControl:

I've been struggling a while with marquee-style image scrolling control.

At a moment, I stuck up with templated ItemsControl:

<Window.Resources>
    <DataTemplate x:Key="itemsTemplate">
        <Image Source="{Binding AbsolutePath}"></Image>
    </DataTemplate>
</Window.Resources>
<ItemsControl ItemTemplate="{StaticResource itemsTemplate}" x:Name="ic"
              ItemsSource="{Binding ElementName=mainWindow, Path=DataItems}" VirtualizingStackPanel.IsVirtualizing="True">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel Orientation="Vertical" VerticalAlignment="Bottom" 
                                    VirtualizingStackPanel.IsVirtualizing="True" >                    
            </VirtualizingStackPanel>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>
开发者_开发技巧

ItemsControl is bound to ObservableCollection, so I can add items at runtime. As soon as item goes off-screen it's removed from ObservableCollection.

The last thing to do is implementing custom item add behavior (smooth slide-in instead of insert-translateothers behavior). Shall I derive from StackPanel to achieve such effect or just perform DoubleAnimation on currently adding item? Any suggestions appreciated.


Check this out: Animate WPF Datatemplate when item added to Listbox. Will it suit your needs?

0

精彩评论

暂无评论...
验证码 换一张
取 消