Skip to content

Name is resolved by name in bindings and storyboards but ignored by XamlReader on non-FrameworkElement objects (WinUI does the opposite) #25346

Open

Description

@MartinZikmund

Current behavior 🐛

Name is treated as a directive in WinUI (DependencyObject_Name), and runtime lookups by name deliberately skip it. Uno resolves it like an ordinary dependency property in some places and ignores it in another, so behavior differs from WinUI in both directions.

Uno is more lenient than WinUI (the Name DP can be found by name on a FrameworkElement):

Scenario (on a Border) WinUI Uno
Binding { Source = border, Path = "Name" }, then border.Name = "B" target keeps "A" (CLR property read, no change notification) target updates to "B" (the DP is resolved and observed)
Binding with Path="(FrameworkElement.Name)" throws ArgumentException (0x80070057) resolves and binds
Storyboard.TargetProperty="Name" or "(FrameworkElement.Name)", then Begin() throws COMException 0x800F1000 no exception, the name is animated

Uno is stricter than WinUI in the runtime XAML parser (XamlReader.Load): a plain Name="..." attribute on a DependencyObject that is not a FrameworkElement is silently dropped.

<Grid>
  <Grid.Resources>
    <MenuFlyout x:Key="k" Name="LPM" />
  </Grid.Resources>
</Grid>

WinUI registers the name (grid.FindName("LPM") returns the MenuFlyout); Uno returns null. Compiled XAML is not affected (WinUI's XAML compiler rejects this markup with WMC0011), so this is limited to XamlReader/hot reload. x:Name works on both.

Expected behavior 🎯

Match WinUI:

  • By-name lookups in bindings and storyboard target paths must not resolve the Name directive. Path=Name binds to the CLR property (no live update), and the attached-style (FrameworkElement.Name) path and Storyboard.TargetProperty on Name fail as they do in WinUI.
  • The runtime XAML parser must resolve a plain Name attribute on any DependencyObject, not only on FrameworkElement.

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

Add this test class to src/Uno.UI.RuntimeTests and run it on Skia Desktop (/runtime-tests). Every test asserts the WinUI behavior, so all five cases fail on Uno today.

[TestClass]
[RunsOnUIThread]
public class Given_NameDirective
{
	private const string Ns = "xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'";

	[TestMethod]
	public void When_Binding_Path_Name_Then_No_Live_Update()
	{
		Border border = new() { Name = "A" };
		TextBlock target = new();
		target.SetBinding(TextBlock.TextProperty, new Binding { Source = border, Path = new PropertyPath("Name") });
		Assert.AreEqual("A", target.Text);

		border.Name = "B";

		Assert.AreEqual("A", target.Text); // Uno: "B"
	}

	[TestMethod]
	public void When_Binding_Path_Attached_FrameworkElement_Name_Then_Throws()
	{
		Border border = new() { Name = "A" };
		TextBlock target = new();
		Assert.ThrowsExactly<ArgumentException>(() =>
		{
			target.SetBinding(TextBlock.TextProperty, new Binding { Source = border, Path = new PropertyPath("(FrameworkElement.Name)") });
			_ = target.Text;
		});
	}

	[TestMethod]
	[DataRow("Name")]
	[DataRow("(FrameworkElement.Name)")]
	public void When_Storyboard_Targets_Name_Then_Begin_Throws(string path)
	{
		Border border = new() { Name = "Anim0" };
		ObjectAnimationUsingKeyFrames animation = new();
		animation.KeyFrames.Add(new DiscreteObjectKeyFrame { KeyTime = TimeSpan.Zero, Value = "Animated" });
		Storyboard.SetTarget(animation, border);
		Storyboard.SetTargetProperty(animation, path);
		Storyboard storyboard = new();
		storyboard.Children.Add(animation);

		try
		{
			Assert.ThrowsExactly<System.Runtime.InteropServices.COMException>(() => storyboard.Begin());
		}
		finally
		{
			storyboard.Stop();
		}
	}

	[TestMethod]
	public void When_XamlReader_Plain_Name_On_NonFrameworkElement_Then_Registered()
	{
		var grid = (Grid)XamlReader.Load($"<Grid {Ns}><Grid.Resources><MenuFlyout x:Key='k' Name='LPM'/></Grid.Resources></Grid>");

		Assert.IsInstanceOfType<MenuFlyout>(grid.FindName("LPM")); // Uno: null
	}
}

Result on Uno master (Skia Desktop): 5 of 5 fail. Binding case: the target reads "B". The attached-path and both storyboard cases: no exception is thrown. The XamlReader case: FindName returns null.

Workaround 🛠️

  • Lenient direction: none needed. Use a regular property if an app relies on {Binding Name, ElementName=x} updating live.
  • Strict direction: use x:Name instead of Name in XAML loaded through XamlReader.

Works on UWP/WinUI

Works on WinUI (WinAppSDK 2.4.0). The WinUI column above was observed in a native WinUI app, and the cause is confirmed in the WinUI C++ sources.

Affected platforms 📱💻🖥️

Skia (all heads share this code). Verified at runtime on Skia Desktop.

Uno.Sdk version (and other relevant versions) 📦

Uno master @ 0599dad (net11.0).

Anything else we need to know? 💬

WinUI side (C++ sources and native runtime check)

  • KnownPropertyIndex::DependencyObject_Name is flagged as a directive: TypeTableStructs.h:342 (IsDirective()).
  • MetadataAPI::TryGetDependencyPropertyByName defaults to allowDirectives = false (MetadataAPI.h:165-169) and skips directives (MetadataAPI.cpp:1292). Binding and storyboard target-path resolution use that default, so Name is not found as a DP.
  • The parser path passes allowDirectives = true (MetadataAPI.cpp:1150, exercised by CanResolveDirectiveOnCustomType in MetadataUnitTests.cpp), which is why a plain Name resolves in XamlReader on any native DependencyObject.
  • The table values were observed in a small unpackaged WinAppSDK 2.4.0 app. It also showed that a custom DependencyObject with its own CLR Name property, set via plain Name=, gets only the CLR property set (no name-scope entry); Uno matches that case.

Uno side (source on master, 0599dad)

  • FrameworkElement.NameProperty is a regular registered DP (FrameworkElement.cs:870), and the by-name lookup (DependencyProperty.InternalGetProperty) has no notion of directives, so binding and storyboard resolution find it.
  • The runtime parser only routes x:Name (member with no declaring type) to the name-scope registration (XamlObjectBuilder.cs:595-608). A plain Name goes through TypeResolver.FindDependencyProperty, which finds nothing on a non-FrameworkElement.

Notes

Activity

  1. added
    kind/bug
    triage/untriaged
    project/animations 🎡
    project/binding 🪢
    area/xaml-reader
    platform/all
    difficulty/medium 🤔
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/xaml-readerdifficulty/medium 🤔kind/bugplatform/allproject/animations 🎡project/binding 🪢triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions