I'm styling a ProgressBar in SL4 and have it nearly done except for the indeterminate animation. This is to be a typed style, and the width of the ProgressBar won't be a fixed value. I'm trying to get set the "To" value in the storyboard, but I'm not having much success...
<DoubleAnimation Duration="00:00:.5" Storyboard.TargetProperty="(Shape.Fill).(LinearGradientBrush.Transform).(TransformGroup.Children)[0].X" Storyboard.TargetName="IndeterminateGradientFill" From="0" To="{Binding ElementName=ProgressBarRootGrid, Path=ActualWi开发者_如何学Godth}"/>
Any suggestions?
I would recommend setting the Shape's HorizontalAlignment to Stretch and then animate the RenderTransforms Scale X property.
This should get your started:
<UserControl x:Class="SilverlightTestImages.MainPage"
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"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
<ControlTemplate x:Key="ProgressBarControlTemplate1" TargetType="ProgressBar">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Determinate"/>
<VisualState x:Name="Indeterminate">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation Duration="0:0:1" To="1" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="rectangle" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border BorderBrush="Black" BorderThickness="1" CornerRadius="2">
<Rectangle x:Name="rectangle" Fill="#FF1B6C0B" RadiusX="1" RadiusY="1" RenderTransformOrigin="0,0.5">
<Rectangle.RenderTransform>
<CompositeTransform ScaleX="0"/>
</Rectangle.RenderTransform>
</Rectangle>
</Border>
</Grid>
</ControlTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<ProgressBar Height="10" VerticalAlignment="Bottom" Template="{StaticResource ProgressBarControlTemplate1}" IsIndeterminate="True"/>
</Grid>
</UserControl>
Update
To accomplish something similar to VS2010 progress bar is a little bit tougher due to some ways the translation animation is setup. Jeff Wilcox from the Silverlight Test team has a nice control that can be fitted to work for your needs. Go to http://www.jeff.wilcox.name/2010/08/performanceprogressbar/ and under 'Get the code' download the RelativeAnimatingContentControl.cs. Then use he following animation, this should be close to what you are looking for
<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"
xmlns:Microsoft_Phone_Controls_Unsupported="clr-namespace:Microsoft.Phone.Controls.Unsupported"
x:Class="SilverlightTestImages.MainPage"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
<ControlTemplate x:Key="ProgressBarControlTemplate1" TargetType="ProgressBar">
<Microsoft_Phone_Controls_Unsupported:RelativeAnimatingContentControl HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" >
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Determinate"/>
<VisualState x:Name="Indeterminate">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation Duration="0:0:1" To="100.1" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="Background" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border BorderBrush="#FFBCBCBC" BorderThickness="1" CornerRadius="2">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFF5F5F5"/>
<GradientStop Color="#FFE5E5E5" Offset="0.49"/>
<GradientStop Color="#FFB4B4B4" Offset="0.5"/>
<GradientStop Color="#FFC8C8C8" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<Grid>
<Border BorderBrush="#B2FFFFFF" BorderThickness="1" CornerRadius="2"/>
<Rectangle x:Name="Background" RadiusX="1" RadiusY="1" RenderTransformOrigin="0,0.5" Width="100" HorizontalAlignment="Left">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#0041DE0C"/>
<GradientStop Color="#9941DE0C" Offset="0.4"/>
<GradientStop Color="#9941DE0C" Offset="0.6"/>
<GradientStop Color="#0041DE0C" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
<Rectangle.RenderTransform>
<CompositeTransform TranslateX="-20.1"/>
</Rectangle.RenderTransform>
</Rectangle>
</Grid>
</Border>
</Microsoft_Phone_Controls_Unsupported:RelativeAnimatingContentControl>
</ControlTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<ProgressBar Height="20" Width="200" VerticalAlignment="Center" HorizontalAlignment="Center" Template="{StaticResource ProgressBarControlTemplate1}" IsIndeterminate="True" />
</Grid>
</UserControl>
精彩评论