Article ID: 955753
RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.
You develop a Winform application and add a ElementHost to host WPF controls in the designer or in the code. The ElementHost's Enabled property is false or at least one of its ancestors' Enabled property is false.
You set the Enabled property above to true at runtime in the code.
The WPF controls on the ElementHost look enabled, but do not respond to mouse or keyboard input.
When the ElementHost window is created HwndSource child window used by WPF is created with the same style. So in this case, the ElementHost window and the HwndSource window are created disabled.
When the Enabled state of a Winforms control is modified, Winforms traverses its child controls and enables/disables them accordingly. However, the HwndSource child control is not enabled/disabled because it is not a .NET control.
So if the ElementHost window is created disabled, HwndSource child window will never get enabled.
You can workaround this problem by always creating ElementHost window enabled. However, this is not as simple as it sounds because its ancestors' Enabled property will also affect its enabled state.
Another workaround is through Win32 Interop. You can derive a class from ElementHost as follows and use it instead of ElementHost:
public class MyElementHost : ElementHost
protected override void OnEnabledChanged(EventArgs e)
private void SynchChildEnableState()
IntPtr childHandle = GetWindow(Handle, GW_CHILD);
if (childHandle != IntPtr.Zero)
private const uint GW_CHILD = 5;
private extern static IntPtr GetWindow(IntPtr hWnd, uint uCmd);
private extern static bool EnableWindow(IntPtr hWnd, bool bEnable);
MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.