WPF / Windows 7中:禁用默认的进度条夜光动画 [英] WPF / Windows 7: Disable Default Progress Bar Glow Animation

查看:180
本文介绍了WPF / Windows 7中:禁用默认的进度条夜光动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速WPF的问题 - 在Win 7(相信Vista的)WPF中,默认的进度条做一个可爱的小彤彤嗖-y动画

我展示了约48个东西在一个屏幕上的进步,它的一点点铺天盖地地拥有所有这些东西呼呼的你 - 你可以仅禁用这些动画没有在应用程序影响默认的动画其余<? / P>

解决方案

我会同意与马修的评论,但无论如何,你的答案是应用自定义样式没有动画。这里的原始风貌(通过反射器),你可以删除/调整/什么:

 &LT;风格X:关键={X:类型进度}的TargetType ={X:类型进度}&GT;
    &LT; Style.Triggers&GT;
        &LT;触发属性=方向值=垂直&GT;
            &LT; setter属性=模板&GT;
                &LT; Setter.Value&GT;
                    &LT;的ControlTemplate的TargetType ={X:类型进度}&GT;
                        &LT; BORDER背景={TemplateBinding背景}了borderThickness ={TemplateBinding了borderThickness}BorderBrush ={TemplateBinding BorderBrush}CornerRadius =3SnapsToDevicePixels =真正的&GT;
                            &所述;边框了borderThickness =1,1,1,0BorderBrush =#BEBEBECornerRadius =2&GT;
                                &所述;边框了borderThickness =1BorderBrush =#EFEFEFCornerRadius =1&GT;
                                    &LT; D​​ockPanel中名称=PART_Track保证金=0,0,0,1LastChildFill =假&GT;
                                        &LT;装饰名称=PART_Indicator码头=底部&GT;
                                            &LT;矩形LayoutTransform ={RotateTransform角= -90}&GT;
                                                &LT; Rectangle.Fill&GT;
                                                    &LT; MultiBinding转换器={主题:ProgressBarBrushConverter}&GT;
                                                        &LT;绑定路径=前景的RelativeSource ={的RelativeSource TemplatedParent}/&GT;
                                                        &LT;绑定路径=IsIndeterminate的RelativeSource ={的RelativeSource TemplatedParent}/&GT;
                                                        &LT;绑定路径=的ActualHeight的ElementName =PART_Indicator/&GT;
                                                        &LT;绑定路径=ActualWidth的的ElementName =PART_Indicator/&GT;
                                                        &LT;绑定路径=的ActualHeight的ElementName =PART_Track/&GT;
                                                    &LT; / MultiBinding&GT;
                                                &LT; /Rectangle.Fill>
                                            &LT; /矩形&GT;
                                        &LT; /装饰&GT;
                                    &LT; / DockPanel中&GT;
                                &LT; /边框&GT;
                            &LT; /边框&GT;
                        &LT; /边框&GT;
                    &LT; /控件模板&GT;
                &LT; /Setter.Value>
            &LT; /二传手&GT;
        &LT; /触发&GT;
    &LT; /Style.Triggers>
    &LT; setter属性=前景VALUE ={的StaticResource [0] N}/&GT;
    &LT; setter属性=背景VALUE ={DynamicResource {X:静态WindowBrush}}/&GT;
    &LT; setter属性=BorderBrushVALUE =#686868/&GT;
    &LT; setter属性=了borderThickness值=1/&GT;
    &LT; setter属性=模板&GT;
        &LT; Setter.Value&GT;
            &LT;的ControlTemplate的TargetType ={X:类型进度}&GT;
                &LT; BORDER背景={TemplateBinding背景}了borderThickness ={TemplateBinding了borderThickness}BorderBrush ={TemplateBinding BorderBrush}CornerRadius =3SnapsToDevicePixels =真正的&GT;
                    &所述;边框了borderThickness =1,1,1,0BorderBrush =#BEBEBECornerRadius =2&GT;
                        &所述;边框了borderThickness =1BorderBrush =#EFEFEFCornerRadius =1&GT;
                            &LT; D​​ockPanel中名称=PART_Track保证金=1,0,0,1LastChildFill =假&GT;
                                &LT;矩形NAME =PART_Indicator&GT;
                                    &LT; Rectangle.Fill&GT;
                                        &LT; MultiBinding转换器={主题:ProgressBarBrushConverter}&GT;
                                            &LT;绑定路径=前景的RelativeSource ={的RelativeSource TemplatedParent}/&GT;
                                            &LT;绑定路径=IsIndeterminate的RelativeSource ={的RelativeSource TemplatedParent}/&GT;
                                            &LT;绑定路径=ActualWidth的的ElementName =PART_Indicator/&GT;
                                            &LT;绑定路径=的ActualHeight的ElementName =PART_Indicator/&GT;
                                            &LT;绑定路径=ActualWidth的的ElementName =PART_Track/&GT;
                                        &LT; / MultiBinding&GT;
                                    &LT; /Rectangle.Fill>
                                &LT; /矩形&GT;
                            &LT; / DockPanel中&GT;
                        &LT; /边框&GT;
                    &LT; /边框&GT;
                &LT; /边框&GT;
            &LT; /控件模板&GT;
        &LT; /Setter.Value>
    &LT; /二传手&GT;
&LT; /样式和GT;
 

和转换器类:

 公共类ProgressBarBrushConverter:IMultiValueConverter
{
//方法
公共对象转换(对象[]值,类型TARGETTYPE,对象参数,CultureInfo的文化)
{
    类型类型= ty​​peof运算(双);
    如果(((((值== NULL)||(values​​.Length!= 5))||((值[0] == NULL)||(值[1] == NULL)))||( ((值[2] == NULL)||(值[3] == NULL))||((值[4] == NULL)||!typeof运算(刷).IsAssignableFrom(值[0] .GetType ()))))||((!typeof运算(布尔).IsAssignableFrom(值[1] .GetType())||!type.IsAssignableFrom(值[2] .GetType()))||(!类型。 IsAssignableFrom(值[3] .GetType())||!type.IsAssignableFrom(值[4] .GetType()))))
    {
        返回null;
    }
    刷=(刷)值[0];
    布尔标志=(布尔)值[1];
    双D =(双)值[2];
    双NUM2 =(双)值[3]。
    双NUM3 =(双)值[4]。
    如果((((D&其中; = 0.0)|| double.IsInfinity(d))的||(double.IsNaN(四)||(NUM2&其中; = 0.0)))||(double.IsInfinity(NUM2)| | double.IsNaN(NUM2)))
    {
        返回null;
    }
    DrawingBrush brush2 =新DrawingBrush();
    brush2.Viewport = brush2.Viewbox =新的矩形(0.0,0.0,D,NUM2);
    brush2.ViewportUnits = brush2.ViewboxUnits = BrushMappingMode.Absolute;
    brush2.TileMode = TileMode.None;
    brush2.Stretch = Stretch.None;
    DrawingGroup组=新DrawingGroup();
    的DrawingContext上下文= group.Open();
    双X = 0.0;
    双幅= 6.0;
    双NUM6 = 2.0;
    双num7 =宽+ NUM6;
    如果(旗)
    {
        INT num8 =(int)的Math.Ceiling((双)(D / num7));
        双num9 = -num8 * num7;
        双num10 = D * 0.3;
        brush2.Viewport = brush2.Viewbox =新的矩形(num9,0.0,num10  -  num9,NUM2);
        TranslateTransform变换=新TranslateTransform();
        双num11 = num8 * 100;
        DoubleAnimationUsingKeyFrames动画=新DoubleAnimationUsingKeyFrames();
        animation.Duration =新的持续时间(TimeSpan.FromMilliseconds(num11));
        animation.RepeatBehavior = RepeatBehavior.Forever;
        的for(int i = 1; I&LT; = num8;我++)
        {
            双num13 = I * num7;
            animation.KeyFrames.Add(新DiscreteDoubleKeyFrame(num13,KeyTime.Uniform));
        }
        transform.BeginAnimation(TranslateTransform.XProperty,动画);
        brush2.Transform =变换;
        而((X +宽)&LT; num10)
        {
            context.DrawRectangle(刷,空,新的矩形(num9 + X,0.0,宽,NUM2));
            X + = num7;
        }
        D = num10;
        X = 0.0;
    }
    而((X +宽)&LT; D​​)
    {
        context.DrawRectangle(刷,空,新的矩形(X,0.0,宽,NUM2));
        X + = num7;
    }
    双num14 = D  -  X;
    如果((标志和安培;及(num14&GT; 0.0))及和放大器;!(Math.Abs​​((双)(D  -  NUM3))&LT; 1E-05))
    {
        context.DrawRectangle(刷,空,新的矩形(X,0.0,num14,NUM2));
    }
    context.Close();
    brush2.Drawing =组;
    返回brush2;
}

公共对象[] ConvertBack(对象的值,类型[] targetTypes,对象参数,CultureInfo的文化)
{
    返回null;
}
}
 

Quick WPF question - on Win 7 (and I assume Vista) in WPF, the default progress bar does a nice little glowing "whoosh"-y animation.

I'm showing progress of about 48 things on one screen, and it's a tad overwhelming to have all of these things whooshing on you - can you disable just these animations without affecting the rest of the default animations in the application?

解决方案

I'd agree with Matthew's comment, but anyway, your answer is to apply a custom style without the animation. Here's the original style (via reflector), you can remove/tweak/whatever:

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

And the converter class:

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

这篇关于WPF / Windows 7中:禁用默认的进度条夜光动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆