Exemplo n.º 1
0
        public void CanOverrideMetadataPropertyChangedCallback()
        {
            using (new DefaultImplementationFixture())
            {
                var raisedParent = new List <IDependencyObject>();
                var raisedChild  = new List <IDependencyObject>();

                var parent = new DependencyObjectFake();
                var child  = new SecondDependencyObjectFake();

                var prop = Dependency.Property.RegisterAttached("AttachedProperty", typeof(string), typeof(DependencyObjectFake), new PropertyMetadata("default", isInherited: true, propertyChangedCallback: (s, e) =>
                {
                    raisedParent.Add(s);
                }));

                prop.OverrideMetadata(typeof(SecondDependencyObjectFake), new PropertyMetadata("overriden", propertyChangedCallback: (s, e) =>
                {
                    raisedChild.Add(s);
                }));

                var childInheritanceSource = child.Component.GetValueSource <InheritanceValueSource>();
                childInheritanceSource.ParentComponent = parent.Component;

                parent.SetValue(prop, "inherited");

                Assert.Collection(raisedParent,
                                  x => Assert.Same(parent, x),
                                  x => Assert.Same(child, x));

                Assert.Collection(raisedChild,
                                  x => Assert.Same(child, x));
            }
        }
Exemplo n.º 2
0
        public void GetAttachedPropertyDefaultValue()
        {
            using (new DefaultImplementationFixture())
            {
                var prop = Dependency.Property.RegisterAttached("IsEnabled", typeof(bool), typeof(DependencyObjectFake), new PropertyMetadata(true));
                var fake = new SecondDependencyObjectFake();

                Assert.True((bool)fake.GetValue(prop));
            }
        }
Exemplo n.º 3
0
        public void SetAttachedReadOnlyPropertyValueViaDP()
        {
            using (new DefaultImplementationFixture())
            {
                var propKey = Dependency.Property.RegisterAttachedReadOnly("IsEnabled", typeof(bool), typeof(DependencyObjectFake), new PropertyMetadata(true));
                var prop    = propKey.DependencyProperty;
                var fake    = new SecondDependencyObjectFake();

                Assert.Throws <InvalidOperationException>(() => fake.SetValue(prop, false));
            }
        }
Exemplo n.º 4
0
        public void SetAttachedReadOnlyPropertyValueViaDPKey()
        {
            using (new DefaultImplementationFixture())
            {
                var propKey = Dependency.Property.RegisterAttachedReadOnly("IsEnabled", typeof(bool), typeof(DependencyObjectFake), new PropertyMetadata(true));
                var fake    = new SecondDependencyObjectFake();

                fake.SetValue(propKey, false);

                Assert.False((bool)fake.GetValue(propKey.DependencyProperty));
            }
        }
Exemplo n.º 5
0
        public void CanOverrideMetadataDefaultValue()
        {
            using (new DefaultImplementationFixture())
            {
                var parent = new DependencyObjectFake();
                var child  = new SecondDependencyObjectFake();

                var prop = Dependency.Property.RegisterAttached("AttachedProperty", typeof(string), typeof(DependencyObjectFake), new PropertyMetadata("default", isInherited: true));
                prop.OverrideMetadata(typeof(SecondDependencyObjectFake), new PropertyMetadata("overriden"));

                var childInheritanceSource = child.Component.GetValueSource <InheritanceValueSource>();
                childInheritanceSource.ParentComponent = parent.Component;

                Assert.Equal("default", parent.GetValue(prop));
                Assert.Equal("overriden", child.GetValue(prop));
            }
        }