0

是否可以在我的 WPF 应用程序中指定一个线程来处理 Visuals 的动画?为了解释更多,在我的应用程序中,有时会有繁重的任务,这会影响 moivng Visuals 的基于数学的动画。

那么,这可能吗?使用专用线程保持动画流畅?

编辑

这是我移动视觉效果的方式:

public class KMouseGrid : Grid
{
private VisualCollection _children;
DrawingVisual DrawingVisual_0;
TranslateTransform _0_translate = new TranslateTransform(0, 0);
DrawingVisual DrawingVisual_1;
TranslateTransform _1_translate = new TranslateTransform(0, 0);

public KMouseGrid()
        {
            MultiInputWrapper.Instance.CoordinateRecieved += new MultiInput.Contracts.MultiInput(Instance_CoordinateRecievedSingleChannel);

            _children.Add(DrawingVisual_0);
            _children.Add(DrawingVisual_1);

        }
void Instance_CoordinateRecievedMultiChannel(double aX, double aY, int aChanelNumber, MultiInput.Contracts.MouseEvents aMouseEvent)
        {
            if (aChanelNumber == 0)
            {
                _0_translate.X = MultiInput.MultiInputMouse.GetLastPosition(0).X  ;
                _0_translate.Y = MultiInput.MultiInputMouse.GetLastPosition(0).Y ;
                //_0_rotate.Angle += 6;
            }
            else if (aChanelNumber == 1)
            {
                _1_translate.X = MultiInput.MultiInputMouse.GetLastPosition(1).X   ;
                _1_translate.Y = MultiInput.MultiInputMouse.GetLastPosition(1).Y  ;
            }


        }


// Provide a required override for the VisualChildrenCount property. 
        protected override int VisualChildrenCount
        {
            get
            {
                if (_children == null)
                {
                    _children = new VisualCollection(this);
                }
                return _children.Count;
            }
        }

        // Provide a required override for the GetVisualChild method. 
        protected override Visual GetVisualChild(int index)
        {
            if (index < 0 || index >= _children.Count)
            {
                throw new ArgumentOutOfRangeException();
            }

            return _children[index];
        }


private DrawingVisual CreateDrawingVisualCursor(ImageSource aImageSource, double aXOffset, double aYOffset)
        {
            DrawingVisual drawingVisual = new DrawingVisual();

            // Retrieve the DrawingContext in order to create new drawing content.
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            // Create a rectangle and draw it in the DrawingContext.
            Rect rect = new Rect(new System.Windows.Point(aXOffset, aYOffset), new System.Windows.Size(aImageSource.Width, aImageSource.Height));
            drawingContext.DrawImage(aImageSource, rect);

            // Persist the drawing content.
            drawingContext.Close();

            return drawingVisual;
        }
4

0 回答 0