Skip to content

Commit

Permalink
Merge pull request #1785 from cwensley/curtis/wpf-customcell-reloaded…
Browse files Browse the repository at this point in the history
…-datacontext

Wpf: Ensure DataContext is set back when CustomCell is reloaded
  • Loading branch information
cwensley committed Sep 17, 2020
2 parents c1f075f + 689c6a9 commit 74486af
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Eto.Wpf/Forms/Cells/CustomCellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class EtoBorder : swc.Border
public Column Column { get; set; }

public string Identifier { get; set; }

public bool NeedsDataContext { get; set; }
}

public class Column : swc.DataGridColumn
Expand Down Expand Up @@ -244,6 +246,7 @@ static void HandleControlDataContextChanged(object sender, sw.DependencyProperty
wpfctl.Child = child.ToNative();
}
handler.Callback.OnConfigureCell(handler.Widget, args, child);
wpfctl.NeedsDataContext = false;

handler.FormatCell(wpfctl, cell, wpfctl.DataContext);
}
Expand All @@ -253,10 +256,23 @@ static void HandleControlLoaded(object sender, sw.RoutedEventArgs e)
// WPF's loaded event is called more than once, e.g. when on a tab that is not initially visible.
var wpfctl = sender as EtoBorder;
var etoctl = wpfctl.Control;
var cell = wpfctl?.GetParent<swc.DataGridCell>();
var col = cell?.Column as Column;
var handler = col?.Handler;

if (etoctl != null && !etoctl.Loaded)
{
etoctl.GetWpfFrameworkElement()?.SetScale(true, true);
etoctl.AttachNative();

// we got loaded, set data context back if needed
if (wpfctl.NeedsDataContext && handler != null)
{
var args = GetEditArgs(handler, cell, wpfctl);
args.SetDataContext(wpfctl.DataContext);
handler.Callback.OnConfigureCell(handler.Widget, args, etoctl);
wpfctl.NeedsDataContext = false;
}
}
}

Expand All @@ -279,6 +295,8 @@ static void HandleControlUnloaded(object sender, sw.RoutedEventArgs e)
var args = GetEditArgs(handler, cell, wpfctl);
args.SetDataContext(null);
handler.Callback.OnConfigureCell(handler.Widget, args, etoctl);

wpfctl.NeedsDataContext = true;
}
}
}
Expand Down

0 comments on commit 74486af

Please sign in to comment.