我正在努力让FluidMoveBehavior工作,但无论我尝试什么都没有动画。它只是正常添加/删除项目而没有任何褪色/滑入/滑出。我从网上下载的其他例子工作得很好,连接似乎很简单。我在下面的代码中做错了什么?
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:SampleData="clr-namespace:Expression.Blend.SampleData.SampleDataSource"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
mc:Ignorable="d"
x:Class="WpfApplication1.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<DataTemplate x:Key="ItemTemplate">
<StackPanel Background="{Binding MyColor}">
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
<ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
<StackPanel>
<i:Interaction.Behaviors>
<ei:FluidMoveBehavior Duration="0:0:5" AppliesTo="Children">
<ei:FluidMoveBehavior.EaseY>
<CubicEase EasingMode="EaseInOut"/>
</ei:FluidMoveBehavior.EaseY>
<ei:FluidMoveBehavior.EaseX>
<CubicEase EasingMode="EaseInOut"/>
</ei:FluidMoveBehavior.EaseX>
</ei:FluidMoveBehavior>
</i:Interaction.Behaviors>
</StackPanel>
</ItemsPanelTemplate>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<ListBox x:Name="lbTest" Margin="8,47,8,8" ItemTemplate="{DynamicResource ItemTemplate}" ItemsPanel="{DynamicResource ItemsPanelTemplate1}" />
<Button Content="Add" HorizontalAlignment="Left" Height="34" Margin="8,9,0,0" VerticalAlignment="Top" Width="100" Click="OnAdd"/>
<Button Content="Remove" HorizontalAlignment="Left" Height="34" Margin="112,9,0,0" VerticalAlignment="Top" Width="100" Click="OnRemove"/>
</Grid>
</Window>
public partial class MainWindow : Window
{
private ObservableCollection<MyItem> items = new ObservableCollection<MyItem>();
private static Random seed;
public MainWindow()
{
this.InitializeComponent();
seed = new Random();
lbTest.ItemsSource = items;
}
private Color GetRandomColor()
{
Color newColor = new Color();
newColor.A = (byte)255;
newColor.R = (byte)seed.Next(0, 256);
newColor.G = (byte)seed.Next(0, 256);
newColor.B = (byte)seed.Next(0, 256);
return newColor;
}
private void OnRemove(object sender, System.Windows.RoutedEventArgs e)
{
if (items.Count > 0)
items.RemoveAt(items.Count - 1);
}
private void OnAdd(object sender, System.Windows.RoutedEventArgs e)
{
items.Add(new MyItem() {
Name = Guid.NewGuid().ToString(),
MyColor = new SolidColorBrush(GetRandomColor())
});
}
}
public class MyItem
{
public string Name
{
get;
set;
}
public Brush MyColor
{
get;
set;
}
}