@@ -82,6 +82,15 @@ public class ChromiumWebBrowser : ContentControl, IRenderWebBrowser, IWpfWebBrow
82
82
/// The dispose count
83
83
/// </summary>
84
84
private int disposeCount ;
85
+ /// <summary>
86
+ /// <summary>
87
+ /// Location of the control on the screen, relative to Top/Left
88
+ /// Used to calculate GetScreenPoint
89
+ /// We're unable to call PointToScreen directly due to treading restrictions
90
+ /// and calling in a sync fashion on the UI thread was problematic.
91
+ /// </summary>
92
+ private Point browserScreenLocation ;
93
+
85
94
/// <summary>
86
95
/// A flag that indicates whether or not the designer is active
87
96
/// NOTE: Needs to be static for OnApplicationExit
@@ -601,15 +610,18 @@ bool IRenderWebBrowser.GetScreenPoint(int viewX, int viewY, out int screenX, out
601
610
screenX = 0 ;
602
611
screenY = 0 ;
603
612
604
- var point = new Point ( viewX , viewY ) ;
605
-
606
- UiThreadRunSync ( ( ) =>
613
+ //We manually claculate the screen point as calling PointToScreen can only be called on the UI thread
614
+ // in a sync fashion and it's easy for users to get themselves into a deadlock.
615
+ if ( DpiScaleFactor > 1 )
616
+ {
617
+ screenX = ( int ) ( browserScreenLocation . X + ( viewX * DpiScaleFactor ) ) ;
618
+ screenY = ( int ) ( browserScreenLocation . Y + ( viewY * DpiScaleFactor ) ) ;
619
+ }
620
+ else
607
621
{
608
- point = PointToScreen ( point ) ;
609
- } ) ;
610
-
611
- screenX = ( int ) point . X ;
612
- screenY = ( int ) point . Y ;
622
+ screenX = ( int ) ( browserScreenLocation . X + viewX ) ;
623
+ screenY = ( int ) ( browserScreenLocation . Y + viewY ) ;
624
+ }
613
625
614
626
return true ;
615
627
}
@@ -1533,6 +1545,7 @@ private void PresentationSourceChangedHandler(object sender, SourceChangedEventA
1533
1545
if ( window != null )
1534
1546
{
1535
1547
window . StateChanged += WindowStateChanged ;
1548
+ window . LocationChanged += OnWindowLocationChanged ;
1536
1549
}
1537
1550
}
1538
1551
}
@@ -1544,6 +1557,7 @@ private void PresentationSourceChangedHandler(object sender, SourceChangedEventA
1544
1557
if ( window != null )
1545
1558
{
1546
1559
window . StateChanged -= WindowStateChanged ;
1560
+ window . LocationChanged -= OnWindowLocationChanged ;
1547
1561
}
1548
1562
}
1549
1563
}
@@ -1574,6 +1588,13 @@ private void WindowStateChanged(object sender, EventArgs e)
1574
1588
}
1575
1589
}
1576
1590
1591
+ private void OnWindowLocationChanged ( object sender , EventArgs e )
1592
+ {
1593
+ //We maintain a manual reference to the controls screen location
1594
+ //(relative to top/left of the screen)
1595
+ browserScreenLocation = PointToScreen ( new Point ( ) ) ;
1596
+ }
1597
+
1577
1598
/// <summary>
1578
1599
/// Removes the source hook.
1579
1600
/// </summary>
@@ -1720,6 +1741,9 @@ private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
1720
1741
Dispatcher
1721
1742
) ;
1722
1743
tooltipTimer . IsEnabled = false ;
1744
+
1745
+ //Initial value for screen location
1746
+ browserScreenLocation = PointToScreen ( new Point ( ) ) ;
1723
1747
}
1724
1748
1725
1749
/// <summary>
0 commit comments