Skip to content

FindName(..) only finds elements in the subtree of the element it is called on.  #14663

Closed as duplicate

Description

@christianfo

Current behavior

If you call FindName("elementName") on a framework element in the XAML tree, on Android and WASM it will succeed if the target element is in the subtree of the element it is called on, but not if it is somewhere else in the XAML tree. By contrast, on Windows FindName(..) finds elements in the entire page, or at least in the whole content under a ContentPresenter.

Expected behavior

Same behavior as on Windows. See above.

How to reproduce it (as minimally and precisely as possible)

The reduced repro is here: UnoApp10.zip

I have the following XAML:

    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
        <Grid>
            <Button Content="Click me!" Click="On_Button_Clicked"/>
        </Grid>
        <TextBlock x:Name="MyTextBlock" Height="400" Width="400"/>
    </StackPanel>

And code that runs FindName(..) on the Button, the Grid, and the StackPanel, logging success of failure in MyTextBlock:

        private void On_Button_Clicked(object sender, RoutedEventArgs e)
        {
            var button = (sender as Button)!;
            TryFindTextBlock(button, "Button");

            var grid = (button.Parent as Grid)!;
            TryFindTextBlock(grid, "Grid");

            var stackPanel = (grid.Parent as StackPanel)!;
            TryFindTextBlock(stackPanel, "StackPanel");
        }

        private void TryFindTextBlock(FrameworkElement fromElement, string elementName)
        {
            var tb = fromElement.FindName("MyTextBlock");
            if (tb != null)
            {
                (tb as TextBlock)!.Text += $"FindName(..) on the {elementName} found MyTextBlock\n";
            }
            else
            {
                MyTextBlock.Text += $"FindName(..) on the {elementName} did NOT find MyTextBlock\n";
            }
        }

Result on Android and WASM:
Screenshot 2023-12-02 144216

While on Windows:
Screenshot 2023-12-02 145114

Workaround

Walk up the tree manually and call FindName on the topmost reachable ancestor.

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageVersion Include="Microsoft.Windows.Compatibility" Version="7.0.5" />
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.4.231008000" />
<PackageVersion Include="Uno.Core.Extensions.Logging.Singleton" Version="4.0.1" />
<PackageVersion Include="Uno.Extensions.Logging.OSLog" Version="1.7.0" />
<PackageVersion Include="Uno.Extensions.Logging.WebAssembly.Console" Version="1.7.0" />
<PackageVersion Include="Uno.Resizetizer" Version="1.2.1" />
<PackageVersion Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="5.0.64" />
<PackageVersion Include="Uno.UniversalImageLoader" Version="1.9.36" />
<PackageVersion Include="Uno.Wasm.Bootstrap" Version="8.0.4" />
<PackageVersion Include="Uno.Wasm.Bootstrap.DevServer" Version="8.0.4" />
<PackageVersion Include="Uno.Wasm.Bootstrap.Server" Version="8.0.4" />
<PackageVersion Include="Uno.WinUI" Version="5.0.64" />
<PackageVersion Include="Uno.WinUI.Lottie" Version="5.0.64" />
<PackageVersion Include="Uno.WinUI.DevServer" Version="5.0.64" />
<PackageVersion Include="Uno.WinUI.WebAssembly" Version="5.0.64" />
<PackageVersion Include="Xamarin.Google.Android.Material" Version="1.10.0.1" />

Affected platforms

WebAssembly, Android

IDE

Visual Studio 2022

IDE version

VS 17.7.6

Relevant plugins

No response

Anything else we need to know?

I did not test it, but presuming the behavior is the same on iOS.

Activity

  1. added
    difficulty/tbd
    kind/bug
    triage/untriaged
    on Dec 2, 2023
  2. jeromelaban commented on Dec 5, 2023

    @jeromelaban
    Member

    Thanks for the report.

    This is something we built as a best effort, but now with the WinUI sources available, we'll be able to make a more accurate implementation.

  3. added
    difficulty/medium 🤔
    area/porting 🖨️
    and removed
    triage/untriaged
    difficulty/tbd
    on Jan 29, 2024
  4. self-assigned this
    on Mar 13, 2024
  5. added theissue type on Jun 20, 2025
  6. MartinZikmund commented on Jul 23, 2025

    @MartinZikmund
    Member
  7. github-actions commented on May 3, 2026

    @github-actions
    Contributor

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or feature requests.

  8. locked as resolved and limited conversation to collaborators on May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/porting 🖨️difficulty/medium 🤔kind/bug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions