WPF / Windows 7:禁用默认进度栏辉光动画

栏目: ASP.NET · 发布时间: 5年前

内容简介:翻译自:https://stackoverflow.com/questions/1523217/wpf-windows-7-disable-default-progress-bar-glow-animation
快速WPF问题 – 在 WPF

上的Win 7(我假设Vista),默认进度条做了一个漂亮的小发光“飞快移动”-y动画.

我在一个屏幕上显示了大约48个内容的进度,并且让所有这些东西都在你身上who – – – – – – – – 你能禁用这些动画而不影响应用程序中的其他默认动画吗?

我同意Matthew的评论,但无论如何,你的答案是在没有动画的情况下应用自定义样式.这是原始样式(通过反射器),你可以删除/调整/不管:

<Style x:Key="{x:Type ProgressBar}" TargetType="{x:Type ProgressBar}">
    <Style.Triggers>
        <Trigger Property="Orientation" Value="Vertical">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ProgressBar}">
                        <Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="3" SnapsToDevicePixels="true">
                            <Border BorderThickness="1,1,1,0" BorderBrush="#BEBEBE" CornerRadius="2">
                                <Border BorderThickness="1" BorderBrush="#EFEFEF" CornerRadius="1">
                                    <DockPanel Name="PART_Track" Margin="0,0,0,1" LastChildFill="false">
                                        <Decorator Name="PART_Indicator" Dock="Bottom">
                                            <Rectangle LayoutTransform="{RotateTransform Angle=-90}">
                                                <Rectangle.Fill>
                                                    <MultiBinding Converter="{theme:ProgressBarBrushConverter}">
                                                        <Binding Path="Foreground" RelativeSource="{RelativeSource TemplatedParent}" />
                                                        <Binding Path="IsIndeterminate" RelativeSource="{RelativeSource TemplatedParent}" />
                                                        <Binding Path="ActualHeight" ElementName="PART_Indicator" />
                                                        <Binding Path="ActualWidth" ElementName="PART_Indicator" />
                                                        <Binding Path="ActualHeight" ElementName="PART_Track" />
                                                    </MultiBinding>
                                                </Rectangle.Fill>
                                            </Rectangle>
                                        </Decorator>
                                    </DockPanel>
                                </Border>
                            </Border>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Trigger>
    </Style.Triggers>
    <Setter Property="Foreground" Value="{StaticResource [0] Ñ}" />
    <Setter Property="Background" Value="{DynamicResource {x:Static WindowBrush}}" />
    <Setter Property="BorderBrush" Value="#686868" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ProgressBar}">
                <Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="3" SnapsToDevicePixels="true">
                    <Border BorderThickness="1,1,1,0" BorderBrush="#BEBEBE" CornerRadius="2">
                        <Border BorderThickness="1" BorderBrush="#EFEFEF" CornerRadius="1">
                            <DockPanel Name="PART_Track" Margin="1,0,0,1" LastChildFill="false">
                                <Rectangle Name="PART_Indicator">
                                    <Rectangle.Fill>
                                        <MultiBinding Converter="{theme:ProgressBarBrushConverter}">
                                            <Binding Path="Foreground" RelativeSource="{RelativeSource TemplatedParent}" />
                                            <Binding Path="IsIndeterminate" RelativeSource="{RelativeSource TemplatedParent}" />
                                            <Binding Path="ActualWidth" ElementName="PART_Indicator" />
                                            <Binding Path="ActualHeight" ElementName="PART_Indicator" />
                                            <Binding Path="ActualWidth" ElementName="PART_Track" />
                                        </MultiBinding>
                                    </Rectangle.Fill>
                                </Rectangle>
                            </DockPanel>
                        </Border>
                    </Border>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

转换器类:

public class ProgressBarBrushConverter : IMultiValueConverter
{
// Methods
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
    Type type = typeof(double);
    if (((((values == null) || (values.Length != 5)) || ((values[0] == null) || (values[1] == null))) || (((values[2] == null) || (values[3] == null)) || ((values[4] == null) || !typeof(Brush).IsAssignableFrom(values[0].GetType())))) || ((!typeof(bool).IsAssignableFrom(values[1].GetType()) || !type.IsAssignableFrom(values[2].GetType())) || (!type.IsAssignableFrom(values[3].GetType()) || !type.IsAssignableFrom(values[4].GetType()))))
    {
        return null;
    }
    Brush brush = (Brush) values[0];
    bool flag = (bool) values[1];
    double d = (double) values[2];
    double num2 = (double) values[3];
    double num3 = (double) values[4];
    if ((((d <= 0.0) || double.IsInfinity(d)) || (double.IsNaN(d) || (num2 <= 0.0))) || (double.IsInfinity(num2) || double.IsNaN(num2)))
    {
        return null;
    }
    DrawingBrush brush2 = new DrawingBrush();
    brush2.Viewport = brush2.Viewbox = new Rect(0.0, 0.0, d, num2);
    brush2.ViewportUnits = brush2.ViewboxUnits = BrushMappingMode.Absolute;
    brush2.TileMode = TileMode.None;
    brush2.Stretch = Stretch.None;
    DrawingGroup group = new DrawingGroup();
    DrawingContext context = group.Open();
    double x = 0.0;
    double width = 6.0;
    double num6 = 2.0;
    double num7 = width + num6;
    if (flag)
    {
        int num8 = (int) Math.Ceiling((double) (d / num7));
        double num9 = -num8 * num7;
        double num10 = d * 0.3;
        brush2.Viewport = brush2.Viewbox = new Rect(num9, 0.0, num10 - num9, num2);
        TranslateTransform transform = new TranslateTransform();
        double num11 = num8 * 100;
        DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames();
        animation.Duration = new Duration(TimeSpan.FromMilliseconds(num11));
        animation.RepeatBehavior = RepeatBehavior.Forever;
        for (int i = 1; i <= num8; i++)
        {
            double num13 = i * num7;
            animation.KeyFrames.Add(new DiscreteDoubleKeyFrame(num13, KeyTime.Uniform));
        }
        transform.BeginAnimation(TranslateTransform.XProperty, animation);
        brush2.Transform = transform;
        while ((x + width) < num10)
        {
            context.DrawRectangle(brush, null, new Rect(num9 + x, 0.0, width, num2));
            x += num7;
        }
        d = num10;
        x = 0.0;
    }
    while ((x + width) < d)
    {
        context.DrawRectangle(brush, null, new Rect(x, 0.0, width, num2));
        x += num7;
    }
    double num14 = d - x;
    if ((!flag && (num14 > 0.0)) && (Math.Abs((double) (d - num3)) < 1E-05))
    {
        context.DrawRectangle(brush, null, new Rect(x, 0.0, num14, num2));
    }
    context.Close();
    brush2.Drawing = group;
    return brush2;
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
    return null;
}
}

翻译自:https://stackoverflow.com/questions/1523217/wpf-windows-7-disable-default-progress-bar-glow-animation


以上所述就是小编给大家介绍的《WPF / Windows 7:禁用默认进度栏辉光动画》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

天使投资

天使投资

唐滔 / 浙江人民出版社 / 2012-4-30 / 56.99元

1.国内首部天使投资的实战手册,堪称创业者的第一本书,打造创业者与天使投资人沟通的最佳桥梁。 2. 薛蛮子、徐小平、雷军、周鸿祎、孙陶然、但斌、曾玉、查立、杨宁、户才和、周哲、莫天全、《创业家》、《创业邦》等联袂推荐。 3.作者唐滔结合他在美国和中国17年的创业和投资经历,为创业者和投资者提供了珍贵和可靠的第一手资料。 4.创业者应何时融资?花多少时间去融资?如何获得融资者青睐?......一起来看看 《天使投资》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

在线进制转换器
在线进制转换器

各进制数互转换器

随机密码生成器
随机密码生成器

多种字符组合密码