WPF Animate Insertion into an ItemsControl - wpf

Earlier I asked about a fade-in,scroll down animation for items control insertion ( Animate Insertions to ItemsControl ). I got the fade-in working but I'm still perplexed about the items control insertion animation. Below is somethings that "sort of" works.
<Grid>
<ScrollViewer>
<ItemsControl Name="TimelineItems"
ItemsSource="{Binding Timeline}"
Style="{StaticResource TimelineStyle}"
ItemContainerStyle="{StaticResource TweetItemStyle}">
<ItemsControl.RenderTransform>
<TransformGroup>
<TranslateTransform />
</TransformGroup>
</ItemsControl.RenderTransform>
<ItemsControl.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.SizeChanged">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="TimelineItems"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)">
<EasingDoubleKeyFrame KeyTime="0"
Value="-50" />
<EasingDoubleKeyFrame KeyTime="0:0:0.5"
Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ItemsControl.Triggers>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Name="MyGrid"
Background="{Binding TweetType, Converter={StaticResource tweetTypeConverter}}"
VerticalAlignment="Top"
HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Style="{StaticResource TweetImageColumnStyle}" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Rectangle Grid.Column="0"
Style="{StaticResource TweetImageStyle}">
<Rectangle.Fill>
<ImageBrush ImageSource="{Binding ProfileImageUrl}" />
</Rectangle.Fill>
</Rectangle>
<StackPanel Grid.Column="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Style="{StaticResource TweetNameStyle}"
Text="{Binding Name}" />
<TextBlock Grid.Column="1"
Style="{StaticResource TweetTimeStyle}"
Text="{Binding TimeAgo}" />
</Grid>
<Controls:TextBlockMarkup Grid.Row="1"
Grid.Column="1"
Markup="{Binding MarkupText}"
Style="{StaticResource TweetStyle}" />
</StackPanel>
<Separator Grid.Row="2"
Grid.ColumnSpan="2"
Style="{StaticResource TweetSeparatorTop}" />
<Separator Grid.Row="3"
Grid.ColumnSpan="2"
Style="{StaticResource TweetSeparatorBottom}" />
</Grid>
<DataTemplate.Resources>
<Storyboard x:Key="ItemAnimation"
AutoReverse="False">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="MyGrid"
Storyboard.TargetProperty="(UIElement.Opacity)">
<EasingDoubleKeyFrame KeyTime="0"
Value="0" />
<EasingDoubleKeyFrame KeyTime="0:0:0.8"
Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</DataTemplate.Resources>
<DataTemplate.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource ItemAnimation}" />
</EventTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
I say "sort of" because the list is offset by a negative offset and then animated into position. The "animation to position" looks great, but the "jump" to a negative offset spoils the affect.
In CSS, I would simply animate the height of the inserted item but I haven't puzzled out how to do this in WPF.
Thoughts?

So, I don't know all details, but I think usual way (I'm noob, lol) are:
Add FluidMove behavior to your visual collection
Insert new object with lower width and height, e.g. 1x1
Animate it to actual size via storyboard or manually DoubleAnimation

Related

WPF more then one DataTrigger

Would you know why the XAML below is not working. It looks like I can not have more than one DataTrigger for an element. Those Storyboards within DataTrigger, as you can tell are being executed on a button click.
The end reason is that on a button click, one grid should slide up, and the other slide down, achieving sort of accordian animation. Thanks
<StackPanel Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,10,0,0">
<!--Add New Banner Grid-->
<!--<Grid DockPanel.Dock="Top" Background="#FFE0FFD2" Height="50">-->
<Grid x:Name="grdAddBunner">
<Grid.Style>
<Style TargetType="Grid">
<Setter Property="Height" Value="50"></Setter>
<Setter Property="Background" Value="#FFE0FFD2"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=btnEditBunner, Path=IsPressed}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height" From="150" To="0" Duration="0:0:0.5"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=btnAddBunner, Path=IsPressed}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height" From="0" To="150" Duration="0:0:0.5"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Content="Add New Banner" HorizontalAlignment="Center" Foreground="DarkGreen" FontWeight="Bold"></Label>
<Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" Content="Fund"></Label>
<telerik:RadComboBox Grid.Row="1" Grid.Column="1" telerik:StyleManager.Theme="Windows8" Margin="3" ItemsSource="{Binding LstFund}"></telerik:RadComboBox>
<Label Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" Content="Banner"></Label>
<TextBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" telerik:StyleManager.Theme="Windows8" Margin="3" Text="{Binding AddBannerName}"></TextBox>
<Button Grid.Row="3" Grid.Column="1" Content="Save" Command="{Binding AddBannerCmd}" Height="25" Width="80" HorizontalAlignment="Left"></Button>
<Button Grid.Row="3" Grid.Column="2" Content="Calcel" Height="25" Width="80" HorizontalAlignment="Right"></Button>
</Grid>
</Grid>
<!--Edit Existing Banner Grid-->
<!--<Grid DockPanel.Dock="Top" Background="#FFFFF7D2" Height="50">-->
<Grid x:Name="grdEditBanner">
<Grid.Style>
<Style TargetType="Grid">
<Setter Property="Height" Value="50"></Setter>
<Setter Property="Background" Value="#FFFFF7D2"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=btnAddBunner, Path=IsPressed}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height" From="150" To="0" Duration="0:0:0.5"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=btnEditBunner, Path=IsPressed}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height" From="0" To="150" Duration="0:0:0.5"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Content="Edit Existing Banner" HorizontalAlignment="Center" Foreground="#FF5B6400" FontWeight="Bold"></Label>
<Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" Content="Fund"></Label>
<telerik:RadComboBox Grid.Row="1" Grid.Column="1" telerik:StyleManager.Theme="Windows8" Margin="3" ItemsSource="{Binding LstFund}" SelectedItem="{Binding SelectedBannerFund}"></telerik:RadComboBox>
<Label Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" Content="Banner"></Label>
<TextBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" telerik:StyleManager.Theme="Windows8" Margin="3" Text="{Binding SelectedBannerName}"></TextBox>
<Button Grid.Row="3" Grid.Column="1" Content="Save" Command="{Binding UpdateBannerCmd}" Height="25" Width="80" HorizontalAlignment="Left"></Button>
<Button Grid.Row="3" Grid.Column="2" Content="Calcel" Height="25" Width="80" HorizontalAlignment="Right"></Button>
</Grid>
</Grid>
</StackPanel>
The "IsPressed" lets you know when the button is "active" this changes again when you release the button.
Have you tried moving this to a command binding on the button and set properties on your viewModel that those grids can use to set styles on themselves?

XAML DoubleAnimation not fully rending items

I'm trying to create a scrolling news feed purly using XAML and am having some trouble with the feed being cut off. right now I'm just using some fake news headlines in my XmlDataProvider, but they will be coming from an RSS feed.
<Window.Resources>
<XmlDataProvider x:Key="NewsFeed" XPath="/rss/Channel/Item">
<x:XData>
<rss xmlns="">
<Channel>
<Item>
<Headline>Cash-Strapped Oklahoma To Conduct Executions By Hammering Squad</Headline>
</Item>
<Item>
<Headline>PetSmart Manager Does Morning Sweep Of Enclosures For Dead Ones Before Opening Doors For Day</Headline>
</Item>
<Item>
<Headline>Lovestruck Arabian Princess Begs Father To Spare John Kerry’s Life</Headline>
</Item>
<Item>
<Headline>Frantic Joe Biden Searching Dog Shelter For Bo Look-Alike</Headline>
</Item>
<Item>
<Headline>Pope Tweets Picture Of Self With God</Headline>
</Item>
<Item>
<Headline>Wes Welker Fielding Offers From Numerous Concussion Researchers</Headline>
</Item>
</Channel>
</rss>
</x:XData>
</XmlDataProvider>
</Window.Resources>
Here is the grid with the Item control that contains the animated text.
<Grid Background="Gray">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="45" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Label Content="RSS" FontSize="16" Margin="10,0,0,0" FontStyle="Italic" Foreground="White" />
<ItemsControl Grid.Row="0" Grid.Column="1" Margin="10,0,10,0" Height="35" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Padding="0" DataContext="{Binding Source={StaticResource NewsFeed}, XPath=/rss/Channel/Item}" ItemsSource="{Binding XPath=//Headline}">
<!-- -->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Center" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<Border BorderBrush="CadetBlue" BorderThickness="2" Height="Auto" Padding="0" HorizontalAlignment="Stretch" VerticalAlignment="Center" ClipToBounds="True">
<StackPanel ClipToBounds="True">
<StackPanel.RenderTransform>
<TranslateTransform x:Name="translate" />
</StackPanel.RenderTransform>
<StackPanel.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation From="1000" To="-1000" Storyboard.TargetName="translate" Storyboard.TargetProperty="X" Duration="0:0:25" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</StackPanel.Triggers>
<ItemsPresenter />
</StackPanel>
</Border>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Background="CadetBlue" Width="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto" ClipToBounds="True" Margin="3">
<TextBlock VerticalAlignment="Center" Foreground="Black" Text="//" Margin="0,0,8,0" ClipToBounds="True" />
<TextBlock VerticalAlignment="Center" Foreground="LightYellow" Text="{Binding Path=InnerText}" Margin="0,0,8,0" ClipToBounds="True" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Control.Margin" Value="5" />
<Setter Property="Control.VerticalAlignment" Value="Stretch" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</Grid>
The animation is working, but is cutting off the third headline. Right now it shows about 3 of the 6 headlines. Why aren't all the headlines being rendered?
Something like this should work:
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<Border BorderBrush="CadetBlue" BorderThickness="2" Height="Auto"
HorizontalAlignment="Stretch" VerticalAlignment="Center"
ClipToBounds="True">
<ItemsPresenter />
</Border>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel.RenderTransform>
<TranslateTransform />
</StackPanel.RenderTransform>
<StackPanel.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation
Storyboard.TargetProperty="RenderTransform.X"
From="1000" To="-1000" Duration="0:0:25" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</StackPanel.Triggers>
</StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

Make a groupbox appear and disappear with fade in fade out animation

in the following example, I don't understand how I could make my "Live Updates" groupbox appear/disappear when the upper checkbox is checked/unchecked. I am looking for a fast fade in/fade out effect in XAML but I am a little lost..
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="WpfControlLibrary1.MainControl"
x:Name="MultiVol" MinHeight="520.12" MinWidth="213">
<Grid HorizontalAlignment="Stretch">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0.966"/>
<GradientStop Color="#FFD7D4FF"/>
</LinearGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel x:Name="LayoutRoot" HorizontalAlignment="Stretch" Grid.Row="0">
<GroupBox Margin="8,0" BorderBrush="#FF88B1D8" HorizontalAlignment="Stretch" Height="99">
<GroupBox.Header>
<WrapPanel>
<Label Content="General" Background="#00000000" Foreground="#FF0033FF" FontWeight="Bold" FontFamily="/WpfControlLibrary1;component/Fonts/#Tahoma" />
</WrapPanel>
</GroupBox.Header>
<UniformGrid Columns="2">
<Label Content="RICs" />
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
<Label Content="Preference" />
<UniformGrid VerticalAlignment="Center" Columns="2" Rows="1">
<RadioButton GroupName="preference" Content="Exotic" IsChecked="False" />
<RadioButton GroupName="preference" Content="Flow" IsChecked="True" />
</UniformGrid>
<Label Content="Live updates" />
<CheckBox IsChecked="True" VerticalAlignment="Center"/>
</UniformGrid>
</GroupBox>
</StackPanel>
<DockPanel Grid.Row="1" HorizontalAlignment="Stretch">
<GroupBox Margin="8,0" BorderBrush="#FF88B1D8" HorizontalAlignment="Stretch">
<GroupBox.Header>
<WrapPanel>
<Label Content="Live updates" Background="#00000000" Foreground="#FF0033FF" FontWeight="Bold" FontFamily="/WpfControlLibrary1;component/Fonts/#Tahoma" />
</WrapPanel>
</GroupBox.Header>
<ListView MinHeight="100" Background="{x:Null}">
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridViewColumn Header="RIC" />
<GridViewColumn Header="Last tick" />
</GridView>
</ListView.View>
</ListView>
</GroupBox>
</DockPanel>
</Grid>
</UserControl>
UPDATE : I get the fade in now, and I tried to add the fade out by adding a Trigger tag :
<DockPanel.Style>
<Style TargetType="{x:Type DockPanel}">
<Style.Triggers>
<Trigger Property="Visibility" Value="Visible">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:0.5" From="0.0" To="1.0" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
<Trigger Property="Visibility" Value="Hidden">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:0.5" From="1.0" To="0.0" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
</DockPanel.Style>
Two steps.
First Visibility:
Create a BooleanToVisibilityConverter in Resources
<UserControl.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</UserControl.Resources>
Give your CheckBox a name
<CheckBox x:Name="LiveUpdateCheckBox" IsChecked="True" VerticalAlignment="Center" />
Bind the DockPanel.Visibility property per ElementName with BooleanToVisibilityConverter
<DockPanel Grid.Row="1" HorizontalAlignment="Stretch"
Visibility="{Binding ElementName=LiveUpdateCheckBox, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
Second Animation:
Create a DockPanel.Style for your LiveUpdates DockPanel
<DockPanel.Style>
<Style TargetType="{x:Type DockPanel}">
<Style.Triggers>
<Trigger Property="Visibility" Value="Visible">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:01" From="0.0" To="1.0" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
</DockPanel.Style>

ItemsControl binding reversing look of items

So, I have a itemsControl which is placed along the bottom of my screen like a status bar.
I have my own usercontrol called "Messenger" which are added to the itemsControl.
The ItemsControl uses a wrappanel with a FlowDirection of RightToLeft so when I add my Messager usercontrol , they start at the right hand side of the screen.
<ItemsControl x:Name="iControl" HorizontalAlignment="Right" VerticalAlignment="Bottom" Height="50" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel FlowDirection="RightToLeft" IsItemsHost="True" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
The messenger looks like the following
<UserControl x:Class="Tester.Messenger"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
x:Name="myUserControl"
>
<UserControl.Resources>
<Geometry x:Key="X">M0,0 L1,1 M0,1 L1,0</Geometry>
<Style x:Key="XButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="Transparent" >
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard Storyboard.TargetName="MouseOverRectangle" Storyboard.TargetProperty="Opacity">
<DoubleAnimation To="1" Duration="00:00:.2"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Path x:Name="path" Margin="2" Data="M0,0 L1,1 M0,1 L1,0" Stroke="LightBlue" Width="10" Height="10" Stretch="Fill"/>
<Rectangle x:Name="MouseOverRectangle" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stroke="White" Opacity="0"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<Grid.RenderTransform>
<TranslateTransform x:Name="translate" Y="50"/>
</Grid.RenderTransform>
<Grid.Triggers>
<EventTrigger RoutedEvent="Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard Storyboard.TargetName="translate" Storyboard.TargetProperty="Y">
<DoubleAnimationUsingKeyFrames>
<LinearDoubleKeyFrame KeyTime="00:00:00" Value="50"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.0" Value="0">
<EasingDoubleKeyFrame.EasingFunction>
<ElasticEase Oscillations="1" Springiness="9" EasingMode="EaseInOut"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Grid.Triggers>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Rectangle MinWidth="100" MinHeight="50" Fill="{Binding ElementName=myUserControl,Path=Fill}" Grid.ColumnSpan="2" Grid.RowSpan="2"/>
<Button x:Name="btnClose" Grid.Column="1" VerticalAlignment="Top" Style="{StaticResource XButtonStyle}" Margin="3,3" Click="btnClose_Click"/>
<TextBlock Text="{Binding ElementName=myUserControl,Path=Header, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="LightGray" FontSize="11" Margin="3,3,0,-3"/>
<TextBlock Grid.Row="1" Grid.ColumnSpan="2" Text="{Binding ElementName=myUserControl,Path=Message, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="White" FontSize="16" Margin="3,-5"/>
</Grid>
When I add "Messenger" usercontrols to my itemsControl manually such as
essenger m = new Messenger();
m.Height = 50;
m.Width = 135;
m.Header = "Kate";
m.Message = "Download File ?";
iControl.Items.Add(m);
everything works fine as expected. But if I databind the ItemsControl itemsource property to some ObservableCollection and add items to the ObservableCollection, then the "Messenger" usercontrols appear reversed. What I mean, is that the textBlocks appear on the right and the X button is on the left. So its a mirror image. I know its probably got something to do with the wrappanel, But I can't figure it out. I hope this makes sense
I have the same problem in that the images in my user control are reversed. My simplified code
<UserControl x:Class="MyApp.Wpf.MainModule.Controls.ButtonImages"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ViewModels="clr-namespace:TheAA.Road.Dispatch.Eva.App.Wpf.MainModule.ViewModels"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
>
<UserControl.Resources>
<ResourceDictionary>
<DataTemplate x:Key="ButtonImageTemplate" DataType="{x:Type ViewModels:ButtonImageViewModel}">
<Image Source="{Binding ButtonProperty.ImageUri}" />
</DataTemplate>
</ResourceDictionary>
</UserControl.Resources>
<WrapPanel Margin="0" Orientation="Horizontal" HorizontalAlignment="Right" FlowDirection="RightToLeft" >
<ItemsControl ItemsSource="{Binding}" ItemTemplate="{StaticResource ButtonImageTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</WrapPanel>
</UserControl>

Silverlight - how to auto begin a Storyboard inside a <ListBox.ItemTemplate>

I'm trying to display a list of bound data in a then get a Canvas to animate behind each row. I'm having trouble getting a Storyboard to Begin when I place it inside a template. Here is an example of the XAML I have so far:
<ListBox x:Name="MyListBox" Background="Transparent" Foreground="White" Height="200" Width="400" BorderThickness="0" Margin="0">
<ListBox.ItemTemplate>
<DataTemplate x:Name="MySingleDataTemplate">
<StackPanel Orientation="Horizontal" x:Name="MySingleStackPanel" Margin="0">
<StackPanel.Resources>
<Storyboard x:Name="MySingleStoryboard" BeginTime="0:0:1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="Canvas99" Storyboard.TargetProperty="Width"
AutoReverse="True" RepeatBehavior="Forever">
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
<LinearDoubleKeyFrame Value="400" KeyTime="0:0:3" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</StackPanel.Resources>
<Grid Background="Black" x:Name="MySingleGrid" Margin="0" ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="Col0" Width="300" />
<ColumnDefinition x:Name="Col1" Width="100" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" x:Name="Row0" />
</Grid.RowDefinitions>
<Canvas Background="{Binding CanvasColour}" Grid.Row="0" Grid.Column="0" x:Name="Canvas99" HorizontalAlignment="Left" />
<TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding Field1}" Margin="0"/>
<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Field2}" Margin="0"/>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
How can I call the equivalent of the C#:
MySingleStoryboard.Begin();
Is there a way I can get it to start from C# or are there some other properties or Triggers I can use in Silverlight? Or am I going about it in completely the wrong way?
thankyou
Mike
Managed to answer my own question! I need to add to my StackPanel, like this:
<StackPanel.Triggers>
<EventTrigger RoutedEvent="StackPanel.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard x:Name="MySingleStoryboard" BeginTime="0:0:1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="Canvas99" Storyboard.TargetProperty="Width"
AutoReverse="True" RepeatBehavior="Forever">
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
<LinearDoubleKeyFrame Value="400" KeyTime="0:0:3" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</StackPanel.Triggers>
Works a treat, now I just need to get rid of all the margins/boarders etc on the listbox and I'll be happy.... for now.
Mike

Resources