Beispiel #1
0
    public Window1()
    {
        InitializeComponent();
        FreezableCollection <SolidColorBrush> collection = new FreezableCollection <SolidColorBrush>();

        collection.Changed += collection_Changed;
        SolidColorBrush brush = new SolidColorBrush(Colors.Red);

        collection.Add(brush);
        brush.Color = Colors.Blue;
    }
        /// <inheritdoc/>
        protected override object ExtendBinding(IServiceProvider serviceProvider, DependencyObject?targetObject, DependencyProperty targetProperty)
        {
            if (targetObject == null)
            {
                return(this);
            }

            UpdateBindingMode(targetObject, targetProperty);

            var binder = new SteppedBinder(targetObject, targetProperty, ActualBinding, SteppingDuration);

            FreezableCollection <TransientBinder> binders = TransientBinder.GetBinders(targetObject);

            binders.Add(binder);

            return(targetObject.GetValue(targetProperty));
        }
Beispiel #3
0
        public void FreezableCollectionBasicTest()
        {
            int    resources1ChangedCount = 0;
            object resourceValue;

            Freezable freezable1 = new Freezable();

            freezable1.ResourcesChanged += (sender, e) => resources1ChangedCount++;

            FreezableCollection <Freezable> freezableCollection = new FreezableCollection <Freezable> {
                freezable1
            };

            FrameworkElement element = new FrameworkElement();

            element.DataContext = "data-context";
            element.Resources   = new ResourceDictionary();
            element.Resources.Add("key1", "value1");

            Assert.IsNull(freezable1.GetValue(FrameworkElement.DataContextProperty));
            Assert.IsFalse(freezable1.TryGetResource("key1", out resourceValue));

            element.SetValue(ValueProperty, freezableCollection);
            Assert.AreEqual("data-context", freezable1.GetValue(FrameworkElement.DataContextProperty));
            Assert.AreEqual(2, resources1ChangedCount);
            Assert.IsTrue(freezable1.TryGetResource("key1", out resourceValue));
            Assert.AreEqual("value1", resourceValue);

            Freezable freezable2 = new Freezable();

            freezableCollection.Add(freezable2);
            Assert.AreEqual("data-context", freezable2.GetValue(FrameworkElement.DataContextProperty));
            Assert.IsTrue(freezable2.TryGetResource("key1", out resourceValue));
            Assert.AreEqual("value1", resourceValue);

            freezableCollection.Clear();
            Assert.AreNotEqual("data-context", freezable1.GetValue(FrameworkElement.DataContextProperty));
            Assert.AreNotEqual("data-context", freezable2.GetValue(FrameworkElement.DataContextProperty));
            Assert.AreEqual(3, resources1ChangedCount);
            Assert.IsFalse(freezable1.TryGetResource("key1", out resourceValue));
            Assert.IsFalse(freezable2.TryGetResource("key1", out resourceValue));
        }
Beispiel #4
0
        public void FreezableCollectionBasicTest()
        {
            int resources1ChangedCount = 0;
            object resourceValue;

            Freezable freezable1 = new Freezable();
            freezable1.ResourcesChanged += (sender, e) => resources1ChangedCount++;

            FreezableCollection<Freezable> freezableCollection = new FreezableCollection<Freezable> { freezable1 };

            FrameworkElement element = new FrameworkElement();
            element.DataContext = "data-context";
            element.Resources = new ResourceDictionary();
            element.Resources.Add("key1", "value1");

            Assert.IsNull(freezable1.GetValue(FrameworkElement.DataContextProperty));
            Assert.IsFalse(freezable1.TryGetResource("key1", out resourceValue));

            element.SetValue(ValueProperty, freezableCollection);
            Assert.AreEqual("data-context", freezable1.GetValue(FrameworkElement.DataContextProperty));
            Assert.AreEqual(2, resources1ChangedCount);
            Assert.IsTrue(freezable1.TryGetResource("key1", out resourceValue));
            Assert.AreEqual("value1", resourceValue);

            Freezable freezable2 = new Freezable();
            freezableCollection.Add(freezable2);
            Assert.AreEqual("data-context", freezable2.GetValue(FrameworkElement.DataContextProperty));
            Assert.IsTrue(freezable2.TryGetResource("key1", out resourceValue));
            Assert.AreEqual("value1", resourceValue);

            freezableCollection.Clear();
            Assert.AreNotEqual("data-context", freezable1.GetValue(FrameworkElement.DataContextProperty));
            Assert.AreNotEqual("data-context", freezable2.GetValue(FrameworkElement.DataContextProperty));
            Assert.AreEqual(3, resources1ChangedCount);
            Assert.IsFalse(freezable1.TryGetResource("key1", out resourceValue));
            Assert.IsFalse(freezable2.TryGetResource("key1", out resourceValue));
        }
Beispiel #5
0
        public void FreezableCollectionBasicTest()
        {
            int    resources1ChangedCount = 0;
            object resourceValue;

            Freezable freezable1 = new Freezable();

            freezable1.ResourcesChanged += (sender, e) => resources1ChangedCount++;

            FreezableCollection <Freezable> freezableCollection = new FreezableCollection <Freezable> {
                freezable1
            };

            FrameworkElement element = new FrameworkElement();

            element.Resources = new ResourceDictionary();
            element.Resources.Add("key1", "value1");

            Assert.IsFalse(freezable1.TryGetResource("key1", out resourceValue));

            freezableCollection.TrySetContextParent(element);
            Assert.AreEqual(1, resources1ChangedCount);
            Assert.IsTrue(freezable1.TryGetResource("key1", out resourceValue));
            Assert.AreEqual("value1", resourceValue);

            Freezable freezable2 = new Freezable();

            freezableCollection.Add(freezable2);
            Assert.IsTrue(freezable2.TryGetResource("key1", out resourceValue));
            Assert.AreEqual("value1", resourceValue);

            freezableCollection.Clear();
            Assert.AreEqual(2, resources1ChangedCount);
            Assert.IsFalse(freezable1.TryGetResource("key1", out resourceValue));
            Assert.IsFalse(freezable2.TryGetResource("key1", out resourceValue));
        }
Beispiel #6
0
 public void Add(ApplicationJumpItem item)
 {
     implementation.AddItem(ApplicationJumpItem.GetItemInfo(item));
     SourceItems.Add(item);
 }