In App.xaml.cs or another instance of the source class, you need to add:
var field = typeof(PresentationSource).GetField("RootSourceProperty", BindingFlags.NonPublic | BindingFlags.Static); var property = (DependencyProperty)field.GetValue(null); property.OverrideMetadata(typeof(DependencyObject), new FrameworkPropertyMetadata(property.DefaultMetadata.DefaultValue, OnHwndSourceChanged));
Where RootSourceProperty is a private field of DependecyProperty of PresentationSource . Its property is used when creating an HwndSource and installing RootVisual. Therefore, you just need to use the modified RootSourceProperty callback RootSourceProperty :
private static void OnHwndSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { }
This is good because you can use it in your application and for all HwndSource ( Popup , Window or user controls where you use HwndSource )
source share