public MainViewModel(TopLevel root) { _root = root; _logicalTree = new TreePageViewModel(this, LogicalTreeNode.Create(root)); _visualTree = new TreePageViewModel(this, VisualTreeNode.Create(root)); _events = new EventsPageViewModel(root); UpdateFocusedControl(); KeyboardDevice.Instance.PropertyChanged += KeyboardPropertyChanged; SelectedTab = 0; _pointerOverSubscription = root.GetObservable(TopLevel.PointerOverElementProperty) .Subscribe(x => PointerOverElement = x?.GetType().Name); Console = new ConsoleViewModel(UpdateConsoleContext); }
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 platformRender = PerspexLocator.Current.GetService <IPlatformRenderInterface>(); if (platformRender == null) { return; } var viewport = platformRender .CreateRenderer(topLevel.PlatformImpl.Handle, initialClientSize.Width, initialClientSize.Height); resources.Add(viewport); resources.Add(topLevel.GetObservable(TopLevel.ClientSizeProperty).Subscribe(clientSize => { viewport.Resize((int)clientSize.Width, (int)clientSize.Height); })); resources.Add(queueManager.RenderNeeded.Subscribe(_ => Dispatcher.UIThread.InvokeAsync(() => topLevel.PlatformImpl.Invalidate(new Rect(topLevel.ClientSize))))); topLevel.PlatformImpl.Paint = rect => { viewport.Render(topLevel); queueManager.RenderFinished(); }; topLevel.Closed += delegate { foreach (var disposable in resources) { disposable.Dispose(); } resources.Clear(); }; }
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 platformRender = PerspexLocator.Current.GetService<IPlatformRenderInterface>(); if(platformRender == null) return; var viewport = platformRender .CreateRenderer(topLevel.PlatformImpl.Handle, initialClientSize.Width, initialClientSize.Height); resources.Add(viewport); resources.Add(topLevel.GetObservable(TopLevel.ClientSizeProperty).Subscribe(clientSize => { viewport.Resize((int) clientSize.Width, (int) clientSize.Height); })); resources.Add(queueManager.RenderNeeded.Subscribe(_ => Dispatcher.UIThread.InvokeAsync(() => topLevel.PlatformImpl.Invalidate(new Rect(topLevel.ClientSize))))); topLevel.PlatformImpl.Paint = rect => { viewport.Render(topLevel); queueManager.RenderFinished(); }; topLevel.Closed += delegate { foreach (var disposable in resources) disposable.Dispose(); resources.Clear(); }; }