예제 #1
0
        public void DependencyPropertyAmbiguityTest()
        {
            ElementB element = new ElementB();

            element.SetValue(ElementA.Value0Property, 1);
            element.SetValue(ElementB.Value0Property2, 2);

            Assert.AreEqual(1, element.GetValue(ElementA.Value0Property));
            Assert.AreEqual(2, element.GetValue(ElementB.Value0Property2));

            Assert.AreEqual(ElementA.Value0Property, DependencyProperty.GetOwnedProperty(typeof(ElementA), "Value0"));
            Assert.AreEqual(ElementB.Value0Property2, DependencyProperty.GetOwnedProperty(typeof(ElementB), "Value0"));

            DependencyProperty[] elementAProperties = new [] { ElementA.Value0Property, ElementA.Value1Property, ElementA.Value2Property, ElementA.Value3Property };
            DependencyProperty[] elementBProperties = new [] { ElementB.Value0Property2 };

            CollectionAssert.AreEqual(elementAProperties, DependencyProperty.GetProperties(typeof(ElementA)).ToArray());
            CollectionAssert.AreEqual(elementBProperties, DependencyProperty.GetProperties(typeof(ElementB)).ToArray());
            CollectionAssert.AreEqual(elementAProperties.Concat(elementBProperties).Cast <object>().ToArray(), DependencyProperty.GetFlattenedProperties(typeof(ElementB)).ToArray());

            try
            {
                DependencyProperty.GetSingleProperty(typeof(ElementB), "Value0");
                Assert.Fail();
            }
            catch
            {
                //
            }

            try
            {
                ElementA.Value0Property.AddOwner(typeof(ElementB));
                Assert.Fail();
            }
            catch
            {
                //
            }
        }