0

In App.xaml.cs or in another starting class instance you need 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 private field DependecyProperty of PresentationSource. Its property use when HwndSource is created and set RootVisual. So you need just use property changed call back of RootSourceProperty:

private static void OnHwndSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {

    }

This is nice because, you can use it in your all Application and for all HwndSource (Popup, Window or Custom controls, where you are using HwndSource)

Smagin Alexey
  • 305
  • 2
  • 6
  • 2
    Cool. What happens next? – 15ee8f99-57ff-4f92-890c-b56153 May 25 '17 at 20:19
  • In this way you hook of creating any HwndSource in your all application - window, popup, cutom control with hwndsource. Of cource you identify type owner of HwndSource throug RootVisual. – Smagin Alexey May 26 '17 at 05:38
  • In avalondocking in floating window is using custom window, which has two HwndSources - one is outside, and other is in inner class. This window using hook message from HwndSource. when i use only outside HwndSource, ihave not full requests from Hook message. It's a reason for many bugs, if you use your custom window over avalong floating window. To fix it you need go to inside this class and through message from inner HwndSource to outside HwndSource. But if you use my solution, you can outside avalon fix this problem – Smagin Alexey May 26 '17 at 10:05
  • Second. You need know about creating popups in all application. Popup use HwndSource inside. Popup doesn't through Loaded event. Opened is simple event. So you will have some problems global hook information about popup. But if you use my solution, you can catch any popup creations – Smagin Alexey May 26 '17 at 10:08
  • Third. Some outher dll use floating controls (HwndSource is inside). This dlls can hide a lot of information about messages from HwndSource. So, if you will use my solution you can fix it without update code of dlls. I think this solution is more better, then low level window hook – Smagin Alexey May 26 '17 at 10:12

0 Answers0