PresentationSource.FromVisual(this) returns null value in WPF
问题 I'm using the following code for my: protected override void OnSourceInitialized(EventArgs e) { ... .... HwndSource source = PresentationSource.FromVisual(this) as HwndSource; ... ... } In some systems the "source" value comes out to be null and i cant find the reason why... 回答1: I think you may have to wait until the UI is rendered until you try to assign the Hwnd. Try putting it in the event handler for Window.Loaded instead. This happened to me before, I had the Hwnd assignment after