Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix removing a control from a TableLayout before it has been initialized #2591

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Eto.Gtk/Forms/TableLayoutHandler.gtk3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ bool Attach(Control child, int x, int y)

public void Remove(Control child)
{
if (controls == null)
return;

for (int y = 0; y < controls.GetLength(0); y++)
{
for (int x = 0; x < controls.GetLength(1); x++)
Expand Down
2 changes: 2 additions & 0 deletions src/Eto.Mac/Forms/TableLayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ public void Move(Control child, int x, int y)

public void Remove(Control child)
{
if (views == null)
return;
for (int y = 0; y < views.GetLength(0); y++)
for (int x = 0; x < views.GetLength(1); x++)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Eto.WinForms/Forms/TableLayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ public void Remove(Control child)
if (childControl.Parent == Control)
{
var pos = Control.GetCellPosition(childControl);
views[pos.Column, pos.Row] = null;
if (views != null)
views[pos.Column, pos.Row] = null;
childControl.Parent = null;
SetEmptyCell(pos.Column, pos.Row);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Eto.Wpf/Forms/TableLayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ public Padding Padding

void Remove(int x, int y)
{
if (controls == null)
return;
var control = controls[x, y];
if (control != null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Eto/Forms/Controls/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,8 @@ public new Container FindParent(string id)
/// </remarks>
public void Detach()
{
if (VisualParent != null)
VisualParent.Remove(this);
VisualParent?.Remove(this);
Parent?.Remove(this);
}

static readonly object IsAttached_Key = new object();
Expand Down
Loading