Esempio n. 1
0
        public static DependencyProperty Add <TOwner, TValue>(
            this DependencyProperty @this,
            Meta <TOwner, TValue> meta,
            DPExtOptions options = DPExtOptions.None)
            where TOwner
        : DependencyObject
        {
            return(@this.AddOwner(
                       typeof(TOwner),
                       new FrameworkPropertyMetadata(
                           options == DPExtOptions.ForceManualInherit
            ? @this.DefaultMetadata.DefaultValue
            : meta.DefaultValue,
                           meta.OptionFlags,
                           (obj, args) =>
            {
                //return true;
                meta.PropertyChangedCallback.Invoke(
                    obj.As <TOwner>(),
                    new DPChangedEventArgs <TValue>(
                        args.Property.As <DependencyProperty>(),
                        args.NewValue.As <TValue>(),
                        args.NewValue.As <TValue>()));
            },
                           (obj, baseValue) =>
            {
                return baseValue;

                meta.CoerceValueCallback(
                    obj.As <TOwner>(),
                    baseValue.As <TValue>());
            })));
        }
        public void Should_Merge_Metadata_If_Supplied()
        {
            FrameworkPropertyMetadata metadata1 = new FrameworkPropertyMetadata(
                "foo",
                FrameworkPropertyMetadataOptions.Inherits,
                this.PropertyChangedCallback1,
                this.CoerceCallback1);

            DependencyProperty dp = DependencyProperty.Register(
                "Should_Merge_Metadata_If_Supplied",
                typeof(string),
                typeof(TestClass1),
                metadata1);

            FrameworkPropertyMetadata metadata2 = new FrameworkPropertyMetadata(
                "bar",
                FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsRender,
                this.PropertyChangedCallback2,
                this.CoerceCallback2);

            dp.AddOwner(typeof(TestClass2), metadata2);

            FrameworkPropertyMetadata result = dp.GetMetadata(typeof(TestClass2)) as FrameworkPropertyMetadata;

            Assert.IsNotNull(result);
            Assert.AreNotSame(metadata1, result);
            Assert.AreSame(metadata2, result);
            Assert.AreEqual("bar", result.DefaultValue);
            Assert.IsTrue(result.Inherits);
            Assert.IsTrue(result.AffectsRender);
            Assert.AreEqual(2, result.PropertyChangedCallback.GetInvocationList().Length);
            Assert.AreEqual(1, result.CoerceValueCallback.GetInvocationList().Length);
        }
        public void TestAddOwnerNullMetadata()
        {
            DependencyProperty p = DependencyProperty.Register("TestAddOwnerNullMetadata", typeof(string), typeof(ObjectPoker));

            p.AddOwner(typeof(SubclassPoker), null);

            PropertyMetadata pm = p.GetMetadata(typeof(SubclassPoker));

            Assert.IsNotNull(pm);
        }
        public void Should_Use_Base_Metadata_If_None_Supplied()
        {
            FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata("foo");
            DependencyProperty        dp       = DependencyProperty.Register(
                "Should_Use_Base_Metadata_If_None_Supplied",
                typeof(string),
                typeof(TestClass1),
                metadata);

            dp.AddOwner(typeof(TestClass2));
            dp.AddOwner(typeof(TestClass3));

            PropertyMetadata metadata1 = dp.GetMetadata(typeof(TestClass1));
            PropertyMetadata metadata2 = dp.GetMetadata(typeof(TestClass2));
            PropertyMetadata metadata3 = dp.GetMetadata(typeof(TestClass3));

            Assert.AreSame(metadata, metadata1);
            Assert.AreSame(metadata1, metadata2);
            Assert.AreSame(metadata2, metadata3);
        }
Esempio n. 5
0
        public static DependencyProperty Add <TOwner, TValue>(
            [NotNull] DependencyProperty property,
            [NotNull] Meta <TOwner, TValue> meta)
            where TOwner : DependencyObject
        {
            meta.IsNotNull(nameof(meta));
            property.IsNotNull(nameof(property));

            return(property.AddOwner(
                       typeof(TOwner),
                       meta));
        }
        public void Should_Not_Change_OwnerType()
        {
            PropertyMetadata   metadata1 = new PropertyMetadata("foo");
            DependencyProperty dp        = DependencyProperty.Register(
                "Should_Not_Change_OwnerType",
                typeof(string),
                typeof(TestClass1),
                metadata1);

            dp.AddOwner(typeof(TestClass2));

            Assert.AreEqual(typeof(TestClass1), dp.OwnerType);
        }
        public void Should_Return_Same_DependencyProperty()
        {
            PropertyMetadata   metadata1 = new PropertyMetadata("foo");
            DependencyProperty dp1       = DependencyProperty.Register(
                "Should_Return_Same_DependencyProperty",
                typeof(string),
                typeof(TestClass1),
                metadata1);

            DependencyProperty dp2 = dp1.AddOwner(typeof(TestClass2));

            Assert.AreSame(dp1, dp2);
        }
Esempio n. 8
0
 /// <summary>
 /// Adds <paramref name="type"/> as owner to <see cref="SizeDefinitionProperty"/>
 /// </summary>
 /// <param name="type">The type to add as owner</param>
 /// <returns>The <see cref="DependencyProperty"/> returned from SizeDefinitionProperty.AddOwner</returns>
 public static DependencyProperty AttachSizeDefinition(Type type)
 {
     return(SizeDefinitionProperty.AddOwner(type,
                                            new FrameworkPropertyMetadata("Large, Middle, Small",
                                                                          FrameworkPropertyMetadataOptions
                                                                          .AffectsArrange |
                                                                          FrameworkPropertyMetadataOptions
                                                                          .AffectsMeasure |
                                                                          FrameworkPropertyMetadataOptions
                                                                          .AffectsRender |
                                                                          FrameworkPropertyMetadataOptions
                                                                          .AffectsParentArrange |
                                                                          FrameworkPropertyMetadataOptions
                                                                          .AffectsParentMeasure,
                                                                          OnSizeDefinitionPropertyChanged)));
 }
        public static void AddCallback(this DependencyProperty dp, System.Type type, PropertyChangedCallback callback)
        {
            if (!Dict.ContainsKey(dp))
            {
                Dict.Add(dp, new List <PropertyChangedCallback>());
                dp.AddOwner(type, new PropertyMetadata((o, args) =>
                {
                    foreach (var cb in Dict[dp])
                    {
                        cb.Invoke(o, args);
                    }
                }));
            }

            Dict[dp].Add(callback);
        }
Esempio n. 10
0
        public void AddOwnered_Class_Should_Return_Overridden_Metadata()
        {
            FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata("foo");
            DependencyProperty        dp       = DependencyProperty.Register(
                "AddOwnered_Class_Should_Return_Overridden_Metadata",
                typeof(string),
                typeof(TestClass1),
                metadata);

            FrameworkPropertyMetadata overridden = new FrameworkPropertyMetadata("bar");

            dp.AddOwner(typeof(TestClass4), overridden);

            PropertyMetadata result = dp.GetMetadata(typeof(TestClass4));

            Assert.AreSame(overridden, result);
        }
        public void Should_Throw_Exception_If_Overridden_With_Less_Derived_Metadata()
        {
            FrameworkPropertyMetadata metadata1 = new FrameworkPropertyMetadata(
                "foo",
                FrameworkPropertyMetadataOptions.Inherits,
                this.PropertyChangedCallback1,
                this.CoerceCallback1);

            DependencyProperty dp = DependencyProperty.Register(
                "Should_Merge_Metadata_If_Supplied",
                typeof(string),
                typeof(TestClass1),
                metadata1);

            PropertyMetadata metadata2 = new PropertyMetadata("bar");

            dp.AddOwner(typeof(TestClass2), metadata2);
        }
Esempio n. 12
0
        public Application()
        {
            //Initialize
            Console.CursorVisible = false;
            Console.Title         = ConsoleTitle;
            UpdateConsoleConfiguration();

            ConsoleTitleProperty.AddOwner(GetType(), new PropertyMetadata((o, args) =>
            {
                if (!ReferenceEquals(o, this))
                {
                    return;
                }

                Console.Title = (string)args.NewValue;
            }));
            BufferSizeProperty.AddOwner(GetType(), new PropertyMetadata(OnUpdateConsoleConfiguration));
            ConsolePositionProperty.AddOwner(GetType(), new PropertyMetadata(OnUpdateConsoleConfiguration));
            ConsoleSizeProperty.AddOwner(GetType(), new PropertyMetadata(OnUpdateConsoleConfiguration));

            for (var y = 0; y < BufferSize.Height; y++)
            {
                for (var x = 0; x < BufferSize.Width; x++)
                {
                    if (y == 0)
                    {
                        Renderer.Buffer[x, y] = new ConsoleElement(' ', ConsoleColor.White, MenuBarColor);
                    }
                    else if (y == BufferSize.Height - 1)
                    {
                        Renderer.Buffer[x, y] = new ConsoleElement(' ', ConsoleColor.White, StatusBarColor);
                    }
                    else
                    {
                        Renderer.Buffer[x, y] = BackgroundElement;
                    }
                }
            }

            Current = this;
        }
Esempio n. 13
0
 protected TitledContainer()
 {
     TitleProperty.AddOwner(GetType(), new PropertyMetadata(OnInvalidated));
     TitleAlignmentProperty.AddOwner(GetType(), new PropertyMetadata(OnInvalidated));
 }
Esempio n. 14
0
 public static DependencyProperty AddOwner(DependencyProperty dp)
 {
     return(dp.AddOwner(OwnerType));
 }
Esempio n. 15
0
 public void Prepare_A1()
 {
     MyAttachedProperty.AddOwner(typeof(DpTestTwo));
 }
Esempio n. 16
0
 protected LabeledComponent()
 {
     TextProperty.AddOwner(GetType(), new PropertyMetadata(OnInvalidated));
 }
 DependencyPropertyRegistrator <T> AddOwner <TProperty>(Expression <Func <T, TProperty> > property, out DependencyProperty propertyField, DependencyProperty sourceProperty, PropertyMetadata metadata)
 {
     propertyField = sourceProperty.AddOwner(typeof(T), metadata);
     return(this);
 }
Esempio n. 18
0
 public static DependencyProperty Add <D, T>(DependencyProperty property, Meta <D, T> meta, DPExtOptions options = DPExtOptions.None) where D : DependencyObject
 => property.AddOwner(typeof(D), new FrameworkPropertyMetadata(options == DPExtOptions.ForceManualInherit ? property.DefaultMetadata.DefaultValue : meta.DefaultValue, meta.Flags,
                                                               meta.ChangedCallback.TryInvoke, meta.CoerceCallback.TryInvoke));
Esempio n. 19
0
 protected ColoredComponent()
 {
     ForegroundColorProperty.AddOwner(GetType(), new PropertyMetadata(OnInvalidated));
     BackgroundColorProperty.AddOwner(GetType(), new PropertyMetadata(OnInvalidated));
 }
Esempio n. 20
0
        public static DependencyProperty AddOwner(this DependencyProperty dp, Type class_type, string prop_name, object?def = null)
        {
            var meta = DPMetaData(true, class_type, prop_name, def);

            return(dp.AddOwner(class_type, meta));
        }
Esempio n. 21
0
 protected Component()
 {
     PositionProperty.AddOwner(GetType(), new PropertyMetadata(OnInvalidated));
 }
Esempio n. 22
0
 public static DependencyProperty AddOwner <T>(DependencyProperty dp, T typeMetadata) where T : PropertyMetadata
 {
     return(dp.AddOwner(OwnerType, typeMetadata));
 }