WPF ProgressBar 半透明滑块动态移动效果 记录以备后用
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="500" Width="600">
<Window.Resources>
<LinearGradientBrush x:Key="ProgressBar" EndPoint="0,0" StartPoint="1,0">
<GradientStop Color="#00000000" Offset="0"/>
<GradientStop Color="Red" Offset="0.4"/>
<GradientStop Color="Red" Offset="0.6"/>
<GradientStop Color="#00000000" Offset="1"/>
</LinearGradientBrush>
</Window.Resources>
<Grid Background="LightBlue">
<ProgressBar Height="35" Margin=" 0 80 0 0 " >
<ProgressBar.Template>
<ControlTemplate>
<ControlTemplate.Resources>
<Storyboard x:Key="IsIndeterminate" RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="Animation">
<EasingDoubleKeyFrame KeyTime="0" Value="0.25"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="0.25"/>
</DoubleAnimationUsingKeyFrames>
<PointAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)" Storyboard.TargetName="Animation">
<EasingPointKeyFrame KeyTime="0" Value="-0.5,0.5"/>
<EasingPointKeyFrame KeyTime="0:0:5" Value="1.5,0.5"/>
</PointAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Border Background="Black">
<Rectangle x:Name="Animation" Visibility="Visible" Fill="{StaticResource ProgressBar}" RenderTransformOrigin="0.5,0.5">
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
</Border>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard Storyboard="{StaticResource IsIndeterminate}"/>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ProgressBar.Template>
</ProgressBar>
</Grid>
</Window>
效果展示
