WPF Simple animation causing performance issues

As you can see below, I have a Canvas that allows you to drag one Thumb control. When the ProgressBars IsIndeterminate parameter is set to false, the thumb is very responsive when you drag it, but as soon as you set it to true, the thumb lags behind a significant number of frames even for such a simple case. When you add additional controls, it becomes very noticeable.

Setting the timeline .DesiredFrameRateProperty does not seem to make any difference.

Is there anything I can do to prevent the problem?

<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); 
    }
}
+4
1

, .

? ?

0

Source: https://habr.com/ru/post/1544322/


All Articles