【问题标题】:WPF Simple animations causing performance issuesWPF 导致性能问题的简单动画
【发布时间】:2014-08-02 18:07:29
【问题描述】:

正如您在下面看到的,我有一个 Canvas 允许您在单个 Thumb 控件周围拖动。将 ProgressBars IsIndeterminate 值设置为 false 时,拇指在您拖动它时会非常灵敏,但一旦您将其设置为 true,即使对于这种简单的情况,拇指也会落后大量帧。当您添加更多控件时,它会变得非常明显。

设置 Timeline.DesiredFrameRateProperty 似乎没有任何区别。

我能做些什么来避免这个问题吗?

<Window x:Class="WpfApplication30.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas>
    <Thumb Width="50"
           Height="50" 
           Canvas.Left="10"
           Canvas.Top="10"
           DragDelta="Thumb_DragDelta"/>

    <ProgressBar Width="200"
                 Height="20"
                 IsIndeterminate="True" />
</Canvas>

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        Timeline.DesiredFrameRateProperty.OverrideMetadata(typeof(Timeline), new FrameworkPropertyMetadata { DefaultValue = 1 });
    }

    private void Thumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
    {
        UIElement obj = sender as UIElement;
        Canvas.SetLeft(obj, Canvas.GetLeft(obj) + e.HorizontalChange);
        Canvas.SetTop(obj, Canvas.GetTop(obj) + e.VerticalChange); 
    }
}

【问题讨论】:

  • 不在我的机器上。甚至没有 5 个酒吧。
  • 您使用的是什么版本的 .Net?
  • 您是否使用自定义 wpf 主题或任何 progresbar 样式?

标签: c# wpf performance animation


【解决方案1】:

我观察到动画进度条会破坏终端服务器的性能。

它只是你的机器吗?您是否正在远程处理并观察此行为?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-24
    • 2011-08-08
    • 2019-05-08
    • 2016-06-20
    • 1970-01-01
    • 2019-05-04
    • 2013-01-17
    相关资源
    最近更新 更多