public WebViewHelperOverlay() { Instance = this; this.InitializeComponent(); this.ToNonActive(); this.CloseButton.Click += (_, __) => { WebViewOverlay.Instance.Hide(); this.Close(); }; }
public void ShowUrl( Window parent, string url, Size?size = null) { this.Url = url; var interopHelper = new WindowInteropHelper(parent); var currentScreen = System.Windows.Forms.Screen.FromHandle(interopHelper.Handle); if (!size.HasValue) { var sizeRatio = Config.Instance.BuiltinBrowserSize / 100d; this.Width = currentScreen.Bounds.Width * sizeRatio; this.Height = currentScreen.Bounds.Height * sizeRatio; } else { this.Width = size.Value.Width; this.Height = size.Value.Height; } this.WebView.Visibility = Visibility.Collapsed; this.ImageBox.Visibility = Visibility.Collapsed; this.Show(); if (!url.IsImage()) { this.WebView.Cursor = Cursors.Wait; this.WebView.Navigate(url); this.ImageView.MouseWheel -= this.Image_MouseWheel; this.MouseWheel -= this.Image_MouseWheel; this.WebView.Visibility = Visibility.Visible; } else { var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.UriSource = new Uri(url); bitmap.EndInit(); this.ImageView.Source = bitmap; this.ImageView.ToolTip = url; this.ImageView.MouseWheel += this.Image_MouseWheel; this.MouseWheel += this.Image_MouseWheel; this.ImageBox.Visibility = Visibility.Visible; } this.Activate(); var closeView = new WebViewHelperOverlay(); closeView.Owner = this; closeView.Show(); closeView.Top = this.Top + this.Height - closeView.Height; closeView.Left = this.Left + this.Width - closeView.Width; }