WPF / Windows 7中:禁用默认的进度条夜光动画(WPF / Windows 7: Dis

2019-08-17 07:44发布

快速WPF的问题 - 在Win 7(和我假设Vista中)在WPF中,默认的进度条做一个可爱的小彤彤“嗖” -y动画。

我一分屏显示的约48事情的进展,这是压倒一点点把所有的这些东西嘶嘶的你 - 你可以在不影响应用程序的默认动画的其余部分仅禁用这些动画?

Answer 1:

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

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


Answer 2:

罗伯特的回答是稳健的。 这里是一个黑客(因为它依赖于做辉光,这是一个实现细节并在后续的版本可以改变元件的内部名称):

void SetGlowVisibility(ProgressBar progressBar, Visibility visibility) {
    var glow = progressBar.Template.FindName("PART_GlowRect", progressBar) as FrameworkElement;
    if (glow != null) glow.Visibility = visibility;
}

如果怎样一个进度条来实现的变化,这个技巧可能会停止工作。

在另一方面,它完全替代了XAML和风格的解决方案可以锁定和固定的颜色,边框等,并有可能被添加到进度在未来的新版本禁止的行为...



Answer 3:

简单的,非动画的进度条可以写成两个填充的矩形网格:左边的人会被填充,比如,用绿色,右边一个灰色的。

该网格将有两个列定义。

改变两者的宽度会使进度变化的影响。



Answer 4:

您也可以一起禁用在Win7这个效果。

桌面上的我的电脑图标上点击右键,选择属性(或按Windows键+暂停/ Break键),单击高级系统设置在左侧窗格中的链接(您也可以在运行中输入SYSDM.CPL打开或开始菜单搜索框,然后按Enter)。 现在点击在性能部分的设置按钮:

取消“动画窗口内控件和元素”,它应该是第一选择。



Answer 5:

不是我的范围,但这个答案可能是太有关: 在Vista的Aero禁用进度条动画



Answer 6:

创建一个快捷方式到您正在使用的应用程序,右键单击该快捷方式并选择属性。 现在,在兼容性选项卡中单击“禁用视觉主题”复选框。



文章来源: WPF / Windows 7: Disable Default Progress Bar Glow Animation