public void Attach(TopLevel topLevel)
        {
            var resources = new List<IDisposable>();
            var initialClientSize = topLevel.PlatformImpl.ClientSize;


            var queueManager = ((IRenderRoot)topLevel).RenderQueueManager;

            if (queueManager == null)
                return;


            var viewport = PlatformManager.CreateRenderTarget(topLevel.PlatformImpl);
            resources.Add(viewport);
            //resources.Add(queueManager.RenderNeeded.Subscribe(_
            //    =>
            //    Dispatcher.UIThread.InvokeAsync(() => topLevel.PlatformImpl.Invalidate(new Rect(topLevel.ClientSize)))));
            Action pendingInvalidation = null;
            resources.Add(queueManager.RenderNeeded.Subscribe(_ =>
            {
                if (pendingInvalidation == null)
                {
                    pendingInvalidation = () =>
                    {
                        topLevel.PlatformImpl.Invalidate(new Rect(topLevel.ClientSize));
                        pendingInvalidation = null;
                    };
                    Dispatcher.UIThread.InvokeAsync(pendingInvalidation);
                }
            }
            ));

            topLevel.PlatformImpl.Paint = rect =>
            {
                viewport.Render(topLevel);
                queueManager.RenderFinished();
            };

            topLevel.Closed += delegate
            {
                foreach (var disposable in resources)
                    disposable.Dispose();
                resources.Clear();
            };
        }
Esempio n. 2
0
 public void SetOwner(TopLevel owner)
 {
     this.owner = owner;
 }
Esempio n. 3
0
 public void SetOwner(TopLevel owner)
 {
     _owner = owner;
 }
Esempio n. 4
0
 private void OnParentChanged(IControl control)
 {
     Unregister();
     _root = (TopLevel) control;
     Register();
 }
Esempio n. 5
0
 private void OnParentChanged(IControl control)
 {
     Unregister();
     _root = (TopLevel)control;
     Register();
 }
Esempio n. 6
0
 /// <summary>
 /// Called when the control is removed to the visual tree.
 /// </summary>
 /// <param name="root">THe root of the visual tree.</param>
 protected override void OnDetachedFromVisualTree(IRenderRoot root)
 {
     base.OnDetachedFromVisualTree(root);
     this.topLevel = null;
 }
Esempio n. 7
0
 /// <summary>
 /// Called when the control is added to the visual tree.
 /// </summary>
 /// <param name="root">THe root of the visual tree.</param>
 protected override void OnAttachedToVisualTree(IRenderRoot root)
 {
     base.OnAttachedToVisualTree(root);
     this.topLevel = root as TopLevel;
 }