Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x:Bind code generation does not recognize dynamic type #10362

Open
sjb-sjb opened this issue Feb 16, 2025 · 0 comments
Open

x:Bind code generation does not recognize dynamic type #10362

sjb-sjb opened this issue Feb 16, 2025 · 0 comments
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners

Comments

@sjb-sjb
Copy link

sjb-sjb commented Feb 16, 2025

Describe the bug

The x:Bind code generation process fails to recognize properties on dynamic type.

Steps to reproduce the bug

Create a class type called PageTag derived from DynamicObject and implementing ICustomPropertyProvider. Create a Page-derived class called PageBase with a DependencyProperty that holds a PageTag and accessed through dynamic type:

        public dynamic? PageTag {
            get { return (PageTag?)this.GetValue(PageTagProperty); }
            set { this.SetValue(PageTagProperty, value); }
        }
        public static DependencyProperty PageTagProperty { get; } = DependencyProperty.Register(nameof(PageBase.PageTag), typeof(PageTag), typeof(PageBase), new PropertyMetadata(default(PageTag)));

Assign an instance of PageTag to the PageTag property, such that the instance object has a dynamically defined string property called 'Name'. Now try binding to PageTag.Name using Binding and x:Bind, e.g.:

        <TextBlock Text="{Binding PageTag.Name, Mode=OneWay, FallbackValue={x:Null}}" />
        <TextBlock Text="{x:Bind PageTag.Name, Mode=OneWay, FallbackValue={x:Null}}" />

The use of Binding works (assuming that DataContext is set correctly). The x:Bind fails at compile time with the message "XamlCompiler error WMC1110: Invalid binding path 'PageTag.Name' : Property 'Name' not found on type 'Object'."

Expected behavior

The message shows that x:Bind is mistakenly replacing 'dynamic' with 'object'. The x:Bind should use the dynamic type in this case, not Object type. It should compile and run.

Screenshots

No response

NuGet package version

None

Windows version

No response

Additional context

No response

@sjb-sjb sjb-sjb added the bug Something isn't working label Feb 16, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners
Projects
None yet
Development

No branches or pull requests

1 participant