Skip to content

Commit

Permalink
Prevent unhandled exception in PointToScreen when not yet visible (ce…
Browse files Browse the repository at this point in the history
…fsharp#2107)

* Fix exception when PresentationSource not set

Prevent PointToScreen() being called if the visual is not yet connected
to a presentation source

* Fix typo

Fix typo
  • Loading branch information
jamespearce2006 authored and merceyz committed Aug 11, 2017
1 parent 8057f32 commit 2c14ac6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions CefSharp.Wpf/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public class ChromiumWebBrowser : ContentControl, IRenderWebBrowser, IWpfWebBrow
/// </summary>
private int disposeCount;
/// <summary>
/// <summary>
/// Location of the control on the screen, relative to Top/Left
/// Used to calculate GetScreenPoint
/// We're unable to call PointToScreen directly due to treading restrictions
Expand Down Expand Up @@ -1547,6 +1546,8 @@ private void PresentationSourceChangedHandler(object sender, SourceChangedEventA
window.StateChanged += WindowStateChanged;
window.LocationChanged += OnWindowLocationChanged;
}

updateBrowserScreenLocation();
}
}
else if (args.OldSource != null)
Expand Down Expand Up @@ -1588,11 +1589,19 @@ private void WindowStateChanged(object sender, EventArgs e)
}
}

private void updateBrowserScreenLocation()
{
if (PresentationSource.FromVisual(this) != null)
{
browserScreenLocation = PointToScreen(new Point());
}
}

private void OnWindowLocationChanged(object sender, EventArgs e)
{
//We maintain a manual reference to the controls screen location
//(relative to top/left of the screen)
browserScreenLocation = PointToScreen(new Point());
updateBrowserScreenLocation();
}

/// <summary>
Expand Down Expand Up @@ -1743,7 +1752,7 @@ private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
tooltipTimer.IsEnabled = false;

//Initial value for screen location
browserScreenLocation = PointToScreen(new Point());
updateBrowserScreenLocation();
}

/// <summary>
Expand Down

0 comments on commit 2c14ac6

Please sign in to comment.