Associating animations with ListViewItem in XAML

I would like to assign an animation to the newly created ListViewItem. Like FadeIn or FadeOut. I have this XAML code:

<ListView Height="320" HorizontalAlignment="Left" Margin="630,0,0,0" Name="listView1" VerticalAlignment="Top" Width="222" ItemsSource="{Binding}"> <ListView.ItemTemplate> <DataTemplate> <Grid Name="mainGrid"> <Grid.ColumnDefinitions> <ColumnDefinition></ColumnDefinition> <ColumnDefinition Width="150"></ColumnDefinition> </Grid.ColumnDefinitions> <Grid.Resources> </Grid.Resources> <Image Name="img" Source="{Binding AvatarSource}" Width="32" Margin="8"></Image> <Image Source="{Binding IconSource}" Width="16" Margin="0,-28,32,0"></Image> <TextBlock Grid.Column="1" Margin="0,8,0,0" TextWrapping="Wrap"> <Run Text="{Binding Name}" FontWeight="Bold"></Run> <LineBreak/> <Run Text="{Binding StatusText}"></Run> </TextBlock> </Grid> </DataTemplate> </ListView.ItemTemplate> </ListView> 

Is there a way to access any method, for example in jQuery: $ ('# listViewItemId'). fadeIn ();

Is it possible to link backViewView1.ItemsSource with any accessible form in which I will see all the controls inside? And how to manipulate them?

I would also like this to not be done manually in C #, but if this cannot be done using the ItemTemplate, I will do it anyway.

I am new to XAML and I have not been able to find a good source for learning XAML with C # properly.

+6
c # wpf xaml
source share
1 answer

Below I have posted the simplest code and XAML that achieves what you want. Go from there to make it work in your own application.

 <Window x:Class="ListviewItemLoadedSpike.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <Storyboard x:Key="FadeIn"> <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:2" From="0" To="1"/> </Storyboard> <Style TargetType="Label" x:Key="FadingLabel"> <Style.Triggers> <EventTrigger RoutedEvent="Loaded"> <BeginStoryboard Storyboard="{StaticResource FadeIn}"/> </EventTrigger> </Style.Triggers> </Style> </Window.Resources> <StackPanel> <ListBox ItemsSource="{Binding Data}"> <ListBox.ItemTemplate> <DataTemplate> <Label Content="{Binding Info}" Style="{StaticResource FadingLabel}"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> <Button Name="AddButton" Click="AddButton_Click"> Add Item </Button> </StackPanel> </Window> using System.Collections.ObjectModel; using System.Windows; namespace ListviewItemLoadedSpike { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { private int counter; public MainWindow() { InitializeComponent(); Data=new ObservableCollection<Datum>(); DataContext = this; } private void AddButton_Click(object sender, RoutedEventArgs e) { counter++; Data.Add(new Datum(counter.ToString())); } public ObservableCollection<Datum> Data { get; set; } } public class Datum { public Datum(string info) { Info = info; } public string Info { get; set; } } } 

Good luck

+5
source share

All Articles