internal static void SetValueBypassPropagation(this Timeline timeline, object value)
        {
            if (timeline.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug))
            {
                timeline.Log().DebugFormat("Setting [{0}] to [{1} / {2}] and bypassing native propagation", value, Storyboard.GetTargetName(timeline), Storyboard.GetTargetProperty(timeline));
            }

            var animatedItem = timeline.PropertyInfo.GetPathItems().Last();

            // Get the property name from the last part of the
            // specified name (for dotted paths, if they exist)
            var propertyName = animatedItem.PropertyName.Split(new[] { '.' }).Last().Replace("(", "").Replace(")", "");

            var dc = animatedItem.DataContext;

            using (dc != null ?
                   DependencyObjectStore.BypassPropagation(
                       (DependencyObject)dc,
                       DependencyProperty.GetProperty(dc.GetType(), propertyName)
                       ) :
                   // DC may have been collected since it's weakly held
                   null
                   )
            {
                timeline.PropertyInfo.Value = value;
            }
        }
Пример #2
0
        public void When_AreDifferent()
        {
            var o1 = new object();
            var o2 = new object();

            // We build our strings from a char array to prevent strings
            // obtained as literals from being reused due to intering
            // in order to ensure that references are different
            // and provide accurate ReferenceEqual results.
            char[] chars = { 'h', 'e', 'l', 'l', 'o' };
            var    s1    = new string(chars);
            var    s2    = new string(chars);

            Assert.IsFalse(DependencyObjectStore.AreDifferent(null, null));
            Assert.IsFalse(DependencyObjectStore.AreDifferent(0, 0));
            Assert.IsFalse(DependencyObjectStore.AreDifferent(0.0, 0.0));
            Assert.IsFalse(DependencyObjectStore.AreDifferent(o1, o1));
            Assert.IsFalse(DependencyObjectStore.AreDifferent(o2, o2));
            Assert.IsFalse(DependencyObjectStore.AreDifferent(s1, s2));
            Assert.IsFalse(DependencyObjectStore.AreDifferent(1.ToString(), 1.ToString()));
            Assert.IsFalse(DependencyObjectStore.AreDifferent("", ""));
            Assert.IsFalse(DependencyObjectStore.AreDifferent("1", "1"));

            Assert.IsTrue(DependencyObjectStore.AreDifferent(0, null));
            Assert.IsTrue(DependencyObjectStore.AreDifferent(null, 0));
            Assert.IsTrue(DependencyObjectStore.AreDifferent(1, 0));
            Assert.IsTrue(DependencyObjectStore.AreDifferent(0, 0.0));
            Assert.IsTrue(DependencyObjectStore.AreDifferent(Visibility.Collapsed, null));
            Assert.IsTrue(DependencyObjectStore.AreDifferent(null, Visibility.Collapsed));
            Assert.IsTrue(DependencyObjectStore.AreDifferent(Visibility.Collapsed, Visibility.Visible));
            Assert.IsTrue(DependencyObjectStore.AreDifferent(Visibility.Visible, Visibility.Collapsed));

            Assert.IsTrue(DependencyObjectStore.AreDifferent(o1, null));
            Assert.IsTrue(DependencyObjectStore.AreDifferent(null, o1));
            Assert.IsTrue(DependencyObjectStore.AreDifferent(o1, o2));

            Assert.IsTrue(DependencyObjectStore.AreDifferent("", null));
            Assert.IsTrue(DependencyObjectStore.AreDifferent("", "1"));
            Assert.IsTrue(DependencyObjectStore.AreDifferent(null, "1"));
            Assert.IsTrue(DependencyObjectStore.AreDifferent("1", "2"));

            var mo1a = new MyObject(1);
            var mo1b = new MyObject(1);
            var mo2  = new MyObject(2);

            Assert.IsFalse(DependencyObjectStore.AreDifferent(mo1a, mo1a));

            Assert.IsTrue(DependencyObjectStore.AreDifferent(mo1a, mo1b));
            Assert.IsTrue(DependencyObjectStore.AreDifferent(mo1b, mo1a));
            Assert.IsTrue(DependencyObjectStore.AreDifferent(mo1a, mo2));
            Assert.IsTrue(DependencyObjectStore.AreDifferent(mo1b, mo2));
        }
Пример #3
0
        public BinderDetails(DependencyObject owner)
        {
            this._store = ((IDependencyObjectStoreProvider)owner).Store;
            this._owner = owner;

            _store.RegisterPropertyChangedCallback(_store.DataContextProperty, Binder_DataContextChanged);
            _store.RegisterPropertyChangedCallback(_store.TemplatedParentProperty, Binder_TemplatedParentChanged);

            _props = DependencyProperty.GetPropertiesForType(owner.GetType());

            DependencyObjectExtensions
            .RegisterDisposablePropertyChangedCallback(_owner, (instance, p, e) => UpdateProperties());
        }
Пример #4
0
        public void When_Set_Parent_As_WeakReferenceProvider()
        {
            var child  = new MyObject(12);
            var parent = new MyProvider();

            var store = new DependencyObjectStore(child, MyObject.DataContextProperty, MyObject.TemplatedParentProperty);

            store.Parent = parent;
            Assert.AreEqual(parent, store.Parent);

            store.Parent = null;
            Assert.AreEqual(null, store.Parent);
        }
Пример #5
0
            internal void SetWeakDataContext(ManagedWeakReference weakDataContext, bool transferReferenceOwnership = false)
            {
                if (!_disposed && DependencyObjectStore.AreDifferent(DataContext, weakDataContext?.Target))
                {
                    var previousStorage = _dataContextWeakStorage;

                    _dataContextWeakStorage = weakDataContext;
                    OnDataContextChanged();

                    // Return the reference to the pool after it's been released from the next BindingItem instances.
                    // Failing to do so makes the reference change without the bindings knowing about it,
                    // making the reference comparison always equal.
                    Uno.UI.DataBinding.WeakReferencePool.ReturnWeakReference(this, previousStorage);
                }
            }
Пример #6
0
        internal static void SetValueBypassPropagation(this Timeline timeline, object value)
        {
            if (timeline.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                timeline.Log().DebugFormat("Setting [{0}] to [{1} / {2}] and bypassing native propagation", value, Storyboard.GetTargetName(timeline), Storyboard.GetTargetProperty(timeline));
            }

            var animatedItem = timeline.PropertyInfo.GetPathItems().Last();

            using (
                DependencyObjectStore.BypassPropagation(
                    (DependencyObject)animatedItem.DataContext,
                    DependencyProperty.GetProperty(animatedItem.DataContext.GetType(), animatedItem.PropertyName)
                    )
                )
            {
                timeline.PropertyInfo.Value = value;
            }
        }