private async void ChangeImage() { try { SetCanvasBackground(_setting.ExpandToIDE); var newimage = await _imageProvider.GetBitmap(); var opacity = _setting.ExpandToIDE && _isMainWindow ? 0.0 : _setting.Opacity; if (_setting.ImageBackgroundType == ImageBackgroundType.Single) { _editorCanvas.Background = new ImageBrush(newimage) { Opacity = opacity, Stretch = _setting.ImageStretch.ConvertTo(), AlignmentX = _setting.PositionHorizon.ConvertTo(), AlignmentY = _setting.PositionVertical.ConvertTo() }; } else { _editorCanvas.Background .AnimateImageSourceChange( new ImageBrush(newimage) { Stretch = _setting.ImageStretch.ConvertTo(), AlignmentX = _setting.PositionHorizon.ConvertTo(), AlignmentY = _setting.PositionVertical.ConvertTo() }, (n) => { _editorCanvas.Background = n; }, new AnimateImageChangeParams { FadeTime = _setting.ImageFadeAnimationInterval, TargetOpacity = opacity } ); } } catch { } }
private void ChangeImage() { try { SetCanvasBackground(); FindWpfTextView(_editorCanvas as DependencyObject); if (_wpfTextViewHost == null) { return; } var newimage = _imageProvider.GetBitmap(); var opacity = _settings.ExpandToIDE && _isMainWindow ? 0.0 : _settings.Opacity; Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.Run(async() => { await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); try { if (_isRootWindow) { var grid = new Grid() { Name = "ClaudiaIdeImage", HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, IsHitTestVisible = false }; var ni = new Image() { Source = newimage, Stretch = _settings.ImageStretch.ConvertTo(), HorizontalAlignment = _settings.PositionHorizon.ConvertToHorizontalAlignment(), VerticalAlignment = _settings.PositionVertical.ConvertToVerticalAlignment(), Opacity = opacity, IsHitTestVisible = false }; grid.Children.Insert(0, ni); Grid.SetRowSpan(grid, 3); Grid.SetColumnSpan(grid, 3); var p = VisualTreeHelper.GetParent(_wpfTextViewHost) as Grid; if (p != null) { foreach (var c in p.Children) { if ((c as Grid)?.Name == "ClaudiaIdeImage") { p.Children.Remove(c as UIElement); break; } } p.Children.Insert(0, grid); } } else { var nib = new ImageBrush(newimage) { Stretch = _settings.ImageStretch.ConvertTo(), AlignmentX = _settings.PositionHorizon.ConvertTo(), AlignmentY = _settings.PositionVertical.ConvertTo(), Opacity = opacity, Viewbox = new Rect(new Point(_settings.ViewBoxPointX, _settings.ViewBoxPointY), new Size(1, 1)) }; _wpfTextViewHost.SetValue(Panel.BackgroundProperty, nib); } _hasImage = true; if (_settings.ImageBackgroundType == ImageBackgroundType.SingleEach) { ((SingleImageEachProvider)_imageProvider).NextImage(); } } catch { } }); } catch { } }
private void ChangeImage() { try { SetCanvasBackground(); FindWpfTextView(_editorCanvas as DependencyObject); if (_wpfTextViewHost == null) { return; } if (!_isTargetWindow) { return; } var newimage = _imageProvider.GetBitmap(); var opacity = _settings.ExpandToIDE && _isMainWindow ? 0.0 : _settings.Opacity; Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.Run(async() => { await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); try { if (_isRootWindow) { var grid = new Grid() { Name = "ClaudiaIdeImage", HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, IsHitTestVisible = false }; var nib = new ImageBrush(newimage) { Stretch = _settings.ImageStretch.ConvertTo(), AlignmentX = _settings.PositionHorizon.ConvertTo(), AlignmentY = _settings.PositionVertical.ConvertTo(), Opacity = opacity, Viewbox = new Rect(new Point(_settings.ViewBoxPointX, _settings.ViewBoxPointY), new Size(1, 1)), TileMode = _settings.TileMode.ConvertTo(), Viewport = new Rect(_settings.ViewPortPointX, _settings.ViewPortPointY, _settings.ViewPortWidth, _settings.ViewPortHeight) }; grid.Background = nib; Grid.SetRowSpan(grid, 3); Grid.SetColumnSpan(grid, 3); if (VisualTreeHelper.GetParent(_wpfTextViewHost) is Grid p) { foreach (var c in p.Children) { if ((c as Grid)?.Name == "ClaudiaIdeImage") { p.Children.Remove(c as UIElement); break; } } p.Children.Insert(0, grid); } } else { var nib = new ImageBrush(newimage) { Stretch = _settings.ImageStretch.ConvertTo(), AlignmentX = _settings.PositionHorizon.ConvertTo(), AlignmentY = _settings.PositionVertical.ConvertTo(), Opacity = opacity, Viewbox = new Rect(new Point(_settings.ViewBoxPointX, _settings.ViewBoxPointY), new Size(1, 1)), TileMode = _settings.TileMode.ConvertTo(), Viewport = new Rect(_settings.ViewPortPointX, _settings.ViewPortPointY, _settings.ViewPortWidth, _settings.ViewPortHeight) }; if (_settings.ImageBackgroundType == ImageBackgroundType.Slideshow) { (_wpfTextViewHost as System.Windows.Controls.Panel).Background.AnimateImageSourceChange( nib, (n) => { (_wpfTextViewHost as System.Windows.Controls.Panel).Background = n; }, new AnimateImageChangeParams { FadeTime = _settings.ImageFadeAnimationInterval, TargetOpacity = opacity } ); } else { _wpfTextViewHost.SetValue(Panel.BackgroundProperty, nib); } } _hasImage = true; if (_settings.ImageBackgroundType == ImageBackgroundType.SingleEach) { ((SingleImageEachProvider)_imageProvider).NextImage(); } } catch { } }); } catch { } }