<ListView Background="Transparent" BorderThickness="0" ScrollViewer.VerticalScrollBarVisibility="Disabled" SelectedValue="{Binding SelectedValue}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Grid Height="80" Background="#00000000">
<Grid.RowDefinitions>
<RowDefinition Height="40*"/>
<RowDefinition Height="20*"/>
</Grid.RowDefinitions>
<Border x:Name="icon" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0 0 0 10" RenderTransformOrigin="0.5,0.5">
<Border.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="iconScale"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Border.RenderTransform>
<Path x:Name="iconPath" Stretch="Fill" Stroke="Transparent" Height="20" Width="20" Data="" Fill="#BBBBBB"/>
</Border>
<Border Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5">
<Border.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="{Binding ElementName=iconScale,Path=ScaleX}" ScaleY="{Binding ElementName=iconScale,Path=ScaleY}"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Border.RenderTransform>
<TextBlock x:Name="iconText" Text="{Binding}" Foreground="#BBBBBB"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="UIElement.MouseEnter">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="icon">
<EasingDoubleKeyFrame KeyTime="0:0:0" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1.5">
<EasingDoubleKeyFrame.EasingFunction>
<ElasticEase EasingMode="EaseOut" Oscillations="2" Springiness="5"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="icon">
<EasingDoubleKeyFrame KeyTime="0:0:0" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1.5">
<EasingDoubleKeyFrame.EasingFunction>
<ElasticEase EasingMode="EaseOut" Oscillations="2" Springiness="5"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="UIElement.MouseLeave">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="icon">
<EasingDoubleKeyFrame KeyTime="0:0:0" Value="1.5"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1">
<EasingDoubleKeyFrame.EasingFunction>
<ElasticEase EasingMode="EaseOut" Oscillations="2" Springiness="5"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="icon">
<EasingDoubleKeyFrame KeyTime="0:0:0" Value="1.5"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1">
<EasingDoubleKeyFrame.EasingFunction>
<ElasticEase EasingMode="EaseOut" Oscillations="2" Springiness="5"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="ListBoxItem.Selected">
<BeginStoryboard>
<Storyboard>
<ColorAnimation To="LightCyan" Duration="0:0:0.2" Storyboard.TargetName="iconPath" Storyboard.TargetProperty="(Path.Stroke).(SolidColorBrush.Color)"/>
<ColorAnimation To="LightCyan" Duration="0:0:0.2" Storyboard.TargetName="iconText" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="ListBoxItem.Unselected">
<BeginStoryboard>
<Storyboard>
<ColorAnimation From="Transparent" Duration="0:0:0.2" Storyboard.TargetName="iconPath" Storyboard.TargetProperty="(Path.Stroke).(SolidColorBrush.Color)"/>
<ColorAnimation To="#BBBBBB" Duration="0:0:0.2" Storyboard.TargetName="iconText" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<DataTrigger Binding="{Binding}" Value="">
<Setter TargetName="iconPath" Property="Data" Value=""/>
</DataTrigger>
<DataTrigger Binding="{Binding}" Value="">
<Setter TargetName="iconPath" Property="Data" Value=""/>
</DataTrigger>
<DataTrigger Binding="{Binding}" Value="">
<Setter TargetName="iconPath" Property="Data" Value=""/>
</DataTrigger>
<DataTrigger Binding="{Binding}" Value="">
<Setter TargetName="iconPath" Property="Data" Value=""/>
</DataTrigger>
<DataTrigger Binding="{Binding}" Value="">
<Setter TargetName="iconPath" Property="Data" Value=""/>
</DataTrigger>
<DataTrigger Binding="{Binding}" Value="">
<Setter TargetName="iconPath" Property="Data" Value=""/>
</DataTrigger>
<DataTrigger Binding="{Binding}" Value="">
<Setter TargetName="iconPath" Property="Data" Value=""/>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>
WPF ListView的几个动画(能够优化显示效果)
最新推荐文章于 2024-09-22 09:58:29 发布
这个博客内容展示了如何使用XAML为ListView创建透明背景、禁用滚动条并自定义ItemContainerStyle。每个列表项包含一个可缩放的图标和文字,通过MouseEnter和MouseLeave事件实现图标缩放的弹性动画。当选中或取消选中列表项时,颜色会发生变化,提供了一种交互式的用户体验。
摘要由CSDN通过智能技术生成