Skip to content

Commit

Permalink
fix: Use FindFirstParent
Browse files Browse the repository at this point in the history
  • Loading branch information
kazo0 committed Feb 8, 2021
1 parent 9978c1e commit 7190e00
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions src/Uno.UI/UI/Xaml/IFrameworkElementImplementation.macOS.tt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ using Windows.UI.Xaml.Automation.Peers;
using Windows.UI.Xaml.Automation.Provider;
using Windows.UI.Xaml.Automation;
using Uno.UI.Xaml;
using Uno.UI.Helpers.WinUI;

using Uno.UI.Extensions;
<#
foreach(var mixin in _mixins) {
#>
Expand Down Expand Up @@ -75,7 +74,7 @@ namespace <#= mixin.NamespaceName #>
{
if(newWindow != null)
{
var parent = GetDependencyObjectAncestor(Superview) as NSView;
var parent = this.FindFirstParent<DependencyObject>() as NSView;
parent ??= Superview;
if(_superViewRef?.GetTarget() == null && parent != null)
{
Expand Down Expand Up @@ -105,26 +104,6 @@ namespace <#= mixin.NamespaceName #>
this.Log().Error($"Failed to process MoveToWindow for {GetType()}", e);
}
}

private static DependencyObject GetDependencyObjectAncestor(NSView firstGuess)
{
var obj = firstGuess;
DependencyObject matchedAncestor = null;
while (obj != null && matchedAncestor == null)
{
matchedAncestor = obj as DependencyObject;
obj = obj.Superview;
}

if (matchedAncestor != null)
{
return matchedAncestor;
}
else
{
return null;
}
}
#endif

// WillMoveToSuperview may not be called if the element is moved into Window immediately.
Expand Down

0 comments on commit 7190e00

Please sign in to comment.