Skip to content

Commit

Permalink
fix: Avoid propagating FindName to Content if ContentTemplate is used
Browse files Browse the repository at this point in the history
Currently we were propagating FindName to the Content view, even if it was "overriden" by the ContentTemplate, which then could result in StackOverflow
  • Loading branch information
MartinZikmund committed Dec 6, 2023
1 parent 767fb71 commit 09e3a0f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Uno.UI/UI/Xaml/IFrameworkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,17 @@ public static IFrameworkElement FindName(IFrameworkElement e, ViewGroup group, s

// If element is a ContentControl with a view as Content, include the view and its children in the search,
// to better match Windows behaviour
var content =
(e as ContentControl)?.Content as IFrameworkElement ??
(e as Controls.Primitives.Popup)?.Child as IFrameworkElement;
IFrameworkElement content = null;
if (e is ContentControl contentControl &&
contentControl.Content is IFrameworkElement innerContent &&
contentControl.ContentTemplate is null) // Only include the Content view if there is no ContentTemplate.
{
content = innerContent;
}
else if (e is Controls.Primitives.Popup popup)
{
content = popup.Child as IFrameworkElement;
}

if (content != null)
{
Expand Down

0 comments on commit 09e3a0f

Please sign in to comment.