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

DependencyProperty.GetMetadata doesn't handle custom types correctly #9939

Open
Youssef1313 opened this issue Aug 31, 2024 · 0 comments
Open
Labels
area-CoreFramework Issues on fundamental components like UIElement, visibility, etc. bug Something isn't working team-Markup Issue for the Markup team

Comments

@Youssef1313
Copy link
Member

Describe the bug

Passing a custom type to DependencyProperty.GetMetadata doesn't get recognized correctly and the returned metadata can have wrong default value.

Steps to reproduce the bug

    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
            When_IsTabStop();
        }

        private partial class CustomFE : FrameworkElement { }
        private partial class CustomControl : Control { }
        private partial class CustomUserControl : UserControl { }

        private static class Assert
        {
            public static void IsFalse(bool b)
            {
                if (b)
                {
                    throw new Exception();
                }
            }

            public static void IsTrue(bool b)
            {
                if (!b)
                {
                    throw new Exception();
                }
            }
        }

        public void When_IsTabStop()
        {
            var customControl = new CustomControl();
            Assert.IsTrue(customControl.IsTabStop);

            var userControl = new UserControl();
            Assert.IsFalse(userControl.IsTabStop);

            var customUserControl = new CustomUserControl();
            Assert.IsFalse(customUserControl.IsTabStop);

            Assert.IsFalse((bool)Control.IsTabStopProperty.GetMetadata(typeof(UIElement)).DefaultValue);
            Assert.IsFalse((bool)Control.IsTabStopProperty.GetMetadata(typeof(FrameworkElement)).DefaultValue);
            Assert.IsFalse((bool)Control.IsTabStopProperty.GetMetadata(typeof(CustomFE)).DefaultValue);
            Assert.IsTrue((bool)Control.IsTabStopProperty.GetMetadata(typeof(Control)).DefaultValue);
            Assert.IsFalse((bool)Control.IsTabStopProperty.GetMetadata(typeof(UserControl)).DefaultValue);
            Assert.IsFalse((bool)Control.IsTabStopProperty.GetMetadata(typeof(CustomUserControl)).DefaultValue);
            Assert.IsTrue((bool)Control.IsTabStopProperty.GetMetadata(typeof(CustomControl)).DefaultValue); // fails
        }
    }

Expected behavior

The last assert should pass

Screenshots

No response

NuGet package version

None

Windows version

No response

Additional context

No response

@Youssef1313 Youssef1313 added the bug Something isn't working label Aug 31, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Aug 31, 2024
@codendone codendone added area-CoreFramework Issues on fundamental components like UIElement, visibility, etc. team-Markup Issue for the Markup team and removed needs-triage Issue needs to be triaged by the area owners labels Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CoreFramework Issues on fundamental components like UIElement, visibility, etc. bug Something isn't working team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

2 participants