mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 11:42:36 +00:00
WinForms - Improve designer support for UserControl
Current DesignMode property is only true when the control is directly interacting with the designer. This checks if an ancestor is in design mode to allow support for UserControls Issue #4057
This commit is contained in:
@@ -490,6 +490,36 @@ namespace CefSharp.WinForms
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if one of the Ancestors of this control is sited
|
||||
/// and that site in DesignMode.
|
||||
/// </summary>
|
||||
// Roughly based on https://github.com/dotnet/winforms/pull/5375
|
||||
private bool IsParentInDesignMode(Control control)
|
||||
{
|
||||
if(control == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(control));
|
||||
}
|
||||
|
||||
//Check if our Site is in DesignMode
|
||||
//If not then walk up the tree
|
||||
//Until we find a Site that is or our parent is null
|
||||
if(control.Site?.DesignMode ?? false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if(control.Parent == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return IsParentInDesignMode(control.Parent);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="E:System.Windows.Forms.Control.HandleCreated" /> event.
|
||||
/// </summary>
|
||||
@@ -498,6 +528,20 @@ namespace CefSharp.WinForms
|
||||
{
|
||||
designMode = DesignMode;
|
||||
|
||||
//Check if our Parent is in design mode.
|
||||
if (!designMode)
|
||||
{
|
||||
try
|
||||
{
|
||||
designMode = IsParentInDesignMode(this);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//TODO: We should log the exception
|
||||
//Need to provide a wrapper around CEF Log first
|
||||
}
|
||||
}
|
||||
|
||||
if(designMode)
|
||||
{
|
||||
//For design mode only we remove our custom ApplicationExit event handler
|
||||
|
||||
Reference in New Issue
Block a user