Silverlight ProgressBar:动态设置InminatedGradientFill?

发布于 2024-11-03 16:22:54 字数 428 浏览 2 评论 0原文

我正在 SL4 中设计一个 ProgressBar,除了不确定的动画之外,它几乎完成了。这是一种类型样式,ProgressBar 的宽度不是固定值。我试图在故事板中设置“To”值,但我没有取得太大成功......

<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=ActualWidth}"/>

有什么建议吗?

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=ActualWidth}"/>

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

面犯桃花 2024-11-10 16:22:54

我建议将 Shape 的 Horizo​​ntalAlignment 设置为 Stretch,然后为 RenderTransforms Scale X 属性设置动画。

这应该可以帮助您开始:

<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>

更新

由于翻译动画的某些设置方式,要完成类似于 VS2010 进度条的操作有点困难。 Silverlight Test 团队的 Jeff Wilcox 有一个很好的控件,可以满足您的需求。转到 http://www.jeff.wilcox.name/2010/08/performanceprogressbar/ 并在“获取代码”下下载RelativeAnimatingContentControl.cs。然后使用以下动画,这应该接近您正在寻找的内容

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文