Exemple #1
0
        public void TestCreateInstanceCore()
        {
            StubTrigger action = new StubTrigger();

            WindowsBase.Freezable freezable = action.GetCreateInstanceCore();
            Assert.AreEqual(freezable.GetType(), typeof(StubTrigger), "freezable.GetType() == typeof(StubTrigger)");
        }
        public void TestCreateInstanceCore()
        {
            StubAction action = new StubAction();

            SysWindows.Freezable freezable = action.GetCreateInstanceCore();
            Assert.AreEqual(freezable.GetType(), typeof(StubAction), "freezable.GetType() == typeof(StubAction)");
        }
Exemple #3
0
        /// <summary>
        ///     Copies data into a cloned instance.
        /// </summary>
        /// <param name="source">
        ///     The original instance to copy data from.
        /// </param>
        /// <remarks>
        ///     When a Freezable's "current value" is cloned, WPF will make
        ///     deep clones of the "current values" of all writable,
        ///     locally-set properties. This has the effect of resolving
        ///     expressions to their values. WPF skips read only DPs.
        ///     
        ///     If you derive from this class and have additional non-DP state
        ///     that should be transfered to copies, you should override the
        ///     CopyCommon method.
        /// </remarks>
        protected sealed override void CloneCurrentValueCore(Freezable source)
        {
            base.CloneCurrentValueCore(source);

            CustomBitmap customBitmapSource = (CustomBitmap)source;
            CopyCore(customBitmapSource, /*useCurrentValue*/ true, /*willBeFrozen*/ false);
        }
Exemple #4
0
        public void FreezableBasicTest()
        {
            int resourcesChangedCount = 0;
            object resourceValue;

            Freezable freezable = new Freezable();
            freezable.ResourcesChanged += (sender, e) => resourcesChangedCount++;

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

            Assert.AreNotEqual("data-context", freezable.GetValue(FrameworkElement.DataContextProperty));
            Assert.IsFalse(freezable.TryGetResource("key1", out resourceValue));

            element.SetValue(ValueProperty, freezable);
            Assert.AreEqual("data-context", freezable.GetValue(FrameworkElement.DataContextProperty));
            Assert.AreEqual(1, resourcesChangedCount);
            Assert.IsTrue(freezable.TryGetResource("key1", out resourceValue));
            Assert.AreEqual("value1", resourceValue);

            element.Resources.Add("key2", "value2");
            Assert.AreEqual(2, resourcesChangedCount);
            Assert.IsTrue(freezable.TryGetResource("key2", out resourceValue));
            Assert.AreEqual("value2", resourceValue);
        }
Exemple #5
0
      /// <summary/>
      protected override void CloneCore(Freezable sourceFreezable) {
         base.CloneCore(sourceFreezable);

         //TODO: Investigate why the following loop is needed. From the API docs, the Children collection should have cloned itself.
         var sourceCollection = ((CompositeEffect)sourceFreezable).Children;
         foreach (var child in sourceCollection) {
            Children.Add((Effect)child.Clone());
         }
      }
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------
        
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods
        
        /// <summary>
        ///     A null-safe wrapper around Freezable.Clone().  (If a null
        ///     is encountered it returns null.)
        /// </summary>
        internal static Freezable Clone(Freezable freezable)
        {
            if (freezable == null)
            {
                return null;
            }

            return freezable.Clone();
        }
        /// <summary>
        ///     Semantically equivilent to Freezable.Clone().Freeze() except that
        ///     GetAsFrozen avoids copying any portions of the Freezable graph
        ///     which are already frozen.
        /// </summary>
        public static Freezable GetAsFrozen(Freezable freezable)
        {
            if (freezable == null)
            {
                return null;
            }

            return freezable.GetAsFrozen();
        }
 /// <summary>
 ///     Stores a frozen copy of defaultValue
 /// </summary>
 internal FreezableDefaultValueFactory(Freezable defaultValue)
 {
     Debug.Assert(defaultValue != null,
         "Null can not be made mutable.  Do not use FreezableDefaultValueFactory.");
     Debug.Assert(defaultValue.CanFreeze,
         "The defaultValue prototype must be freezable.");
     
     _defaultValuePrototype = defaultValue.GetAsFrozen();
 }
            public FreezableProxyCommand(Freezable freezable, string name)
                : base(null, name)
            {
                _freezable = freezable;

                var evt = _freezable.GetType().GetEvent("InheritanceContextChanged",
                    BindingFlags.Instance | BindingFlags.NonPublic);
                var addMethod = evt.GetAddMethod(true);
                addMethod.Invoke(freezable, new[] {new EventHandler(OnInheritanceContextChanged)});

                SetFrameworkElementFromInheritanceContext();
            }
        /// <summary>
        /// If freezable is already frozen, it returns freezable
        /// If freezable is not frozen, it returns a copy that is frozen if possible
        /// </summary>
        internal static Freezable GetAsFrozenIfPossible(Freezable freezable)
        {
            if (freezable == null)
            {
                return null;
            }

            if (freezable.CanFreeze)
            {
                freezable = freezable.GetAsFrozen();
            }

            return freezable;
        }
Exemple #11
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));
        }
Exemple #12
0
 protected override void GetCurrentValueAsFrozenCore(Freezable source)
 {
     Invariant.Assert(false);
 }
Exemple #13
0
 protected override void CloneCurrentValueCore(Freezable source)
 {
     Invariant.Assert(false);
 }
		/// <summary>
		/// Makes the s_instance a clone (deep copy) of the specified <see cref="Freezable"/>
		/// using base (non-animated) property values. 
		/// </summary>
		/// <param name="sourceFreezable">
		/// The object to clone.
		/// </param>
		protected sealed override void CloneCore(Freezable sourceFreezable)
		{
			base.CloneCore(sourceFreezable);
		}
        protected override void GetCurrentValueAsFrozenCore(Freezable sourceFreezable)
        {
            WriteableBitmap sourceBitmap = (WriteableBitmap)sourceFreezable;

            base.GetCurrentValueAsFrozenCore(sourceFreezable);

            CopyCommon(sourceBitmap);
        }
        protected override void CloneCurrentValueCore(Freezable sourceFreezable)
        {
            WriteableBitmap sourceBitmap = (WriteableBitmap) sourceFreezable;

            base.CloneCurrentValueCore(sourceFreezable);

            CopyCommon(sourceBitmap);
        }
        private static bool DefaultFreezeValueCallback(
            DependencyObject d,
            DependencyProperty dp,
            EntryIndex entryIndex,
            PropertyMetadata metadata,
            bool isChecking)
        {
            // The expression check only needs to be done when isChecking is true
            // because if we return false here the Freeze() call will fail.
            if (isChecking)
            {
                if (d.HasExpression(entryIndex, dp))
                {
                    if (TraceFreezable.IsEnabled)
                    {
                        TraceFreezable.Trace(
                            TraceEventType.Warning,
                            TraceFreezable.UnableToFreezeExpression,
                            d,
                            dp,
                            dp.OwnerType);
                    }

                    return(false);
                }
            }

            if (!dp.IsValueType)
            {
                object value =
                    d.GetValueEntry(
                        entryIndex,
                        dp,
                        metadata,
                        RequestFlags.FullyResolved).Value;

                if (value != null)
                {
                    Freezable valueAsFreezable = value as Freezable;

                    if (valueAsFreezable != null)
                    {
                        if (!valueAsFreezable.Freeze(isChecking))
                        {
                            if (TraceFreezable.IsEnabled)
                            {
                                TraceFreezable.Trace(
                                    TraceEventType.Warning,
                                    TraceFreezable.UnableToFreezeFreezableSubProperty,
                                    d,
                                    dp,
                                    dp.OwnerType);
                            }

                            return(false);
                        }
                    }
                    else  // not a Freezable
                    {
                        DispatcherObject valueAsDispatcherObject = value as DispatcherObject;

                        if (valueAsDispatcherObject != null)
                        {
                            if (valueAsDispatcherObject.Dispatcher == null)
                            {
                                // The property is a free-threaded DispatcherObject; since it's
                                // already free-threaded it doesn't prevent this Freezable from
                                // becoming free-threaded too.
                                // It is up to the creator of this type to ensure that the
                                // DispatcherObject is actually immutable
                            }
                            else
                            {
                                // The value of this property derives from DispatcherObject and
                                // has thread affinity; return false.

                                if (TraceFreezable.IsEnabled)
                                {
                                    TraceFreezable.Trace(
                                        TraceEventType.Warning,
                                        TraceFreezable.UnableToFreezeDispatcherObjectWithThreadAffinity,
                                        d,
                                        dp,
                                        dp.OwnerType,
                                        valueAsDispatcherObject);
                                }

                                return(false);
                            }
                        }

                        // The property isn't a DispatcherObject.  It may be immutable (such as a string)
                        // or the user may have made it thread-safe.  It's up to the creator of the type to
                        // do the right thing; we return true as an extensibility point.
                    }
                }
            }

            return(true);
        }
        /// <summary>
        /// Implementation of <see cref="System.Windows.Freezable.GetAsFrozenCore(Freezable)">Freezable.GetAsFrozenCore</see>.
        /// </summary>
        protected override void GetAsFrozenCore(Freezable source)
        {
            DecimalAnimationUsingKeyFrames sourceAnimation = (DecimalAnimationUsingKeyFrames) source;
            base.GetAsFrozenCore(source);

            CopyCommon(sourceAnimation, /* isCurrentValueClone = */ false);
        }
	protected override void GetCurrentValueAsFrozenCore (Freezable sourceFreezable)
	{
		throw new NotImplementedException ();
	}
        protected override void GetCurrentValueAsFrozenCore(Freezable sourceFreezable)
        {
            base.GetCurrentValueAsFrozenCore(sourceFreezable);

            CloneCommon(sourceFreezable);
        } 
 //
 // Summary:
 //     Makes the current instance a frozen clone of the specified System.Windows.Freezable.
 //     If the object has animated dependency properties, their current animated
 //     values are copied.
 //
 // Parameters:
 //   sourceFreezable:
 //     The System.Windows.Freezable to copy and freeze.
 protected virtual void GetCurrentValueAsFrozenCore(Freezable sourceFreezable)
 {
     Contract.Requires(sourceFreezable != null);
 }
        /// <summary>
        /// Implementation of <see cref="System.Windows.Freezable.GetCurrentValueAsFrozenCore(Freezable)">Freezable.GetCurrentValueAsFrozenCore</see>.
        /// </summary>
        protected override void GetCurrentValueAsFrozenCore(Freezable source)
        {
            CharAnimationUsingKeyFrames sourceAnimation = (CharAnimationUsingKeyFrames) source;
            base.GetCurrentValueAsFrozenCore(source);

            CopyCommon(sourceAnimation, /* isCurrentValueClone = */ true);
        }
 //
 // Summary:
 //     Makes the instance a modifiable clone (deep copy) of the specified System.Windows.Freezable
 //     using current property values.
 //
 // Parameters:
 //   sourceFreezable:
 //     The System.Windows.Freezable to be cloned.
 protected virtual void CloneCurrentValueCore(Freezable sourceFreezable)
 {
 }
        // Token: 0x06000691 RID: 1681 RVA: 0x00014908 File Offset: 0x00012B08
        internal DependencyObject InstantiateTree(UncommonField <HybridDictionary[]> dataField, DependencyObject container, DependencyObject parent, List <DependencyObject> affectedChildren, ref List <DependencyObject> noChildIndexChildren, ref FrugalStructList <ChildPropertyDependent> resourceDependents)
        {
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose, EventTrace.Event.WClientParseFefCrInstBegin);
            FrameworkElement frameworkElement = container as FrameworkElement;
            bool             flag             = frameworkElement != null;
            DependencyObject dependencyObject = null;

            if (this._text != null)
            {
                IAddChild addChild = parent as IAddChild;
                if (addChild == null)
                {
                    throw new InvalidOperationException(SR.Get("TypeMustImplementIAddChild", new object[]
                    {
                        parent.GetType().Name
                    }));
                }
                addChild.AddText(this._text);
            }
            else
            {
                dependencyObject = this.CreateDependencyObject();
                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose, EventTrace.Event.WClientParseFefCrInstEnd);
                FrameworkObject frameworkObject = new FrameworkObject(dependencyObject);
                Visual3D        visual3D        = null;
                bool            flag2           = false;
                if (!frameworkObject.IsValid)
                {
                    visual3D = (dependencyObject as Visual3D);
                    if (visual3D != null)
                    {
                        flag2 = true;
                    }
                }
                bool isFE = frameworkObject.IsFE;
                if (!flag2)
                {
                    FrameworkElementFactory.NewNodeBeginInit(isFE, frameworkObject.FE, frameworkObject.FCE);
                    if (StyleHelper.HasResourceDependentsForChild(this._childIndex, ref resourceDependents))
                    {
                        frameworkObject.HasResourceReference = true;
                    }
                    FrameworkElementFactory.UpdateChildChains(this._childName, this._childIndex, isFE, frameworkObject.FE, frameworkObject.FCE, affectedChildren, ref noChildIndexChildren);
                    FrameworkElementFactory.NewNodeStyledParentProperty(container, flag, isFE, frameworkObject.FE, frameworkObject.FCE);
                    if (this._childIndex != -1)
                    {
                        StyleHelper.CreateInstanceDataForChild(dataField, container, dependencyObject, this._childIndex, this._frameworkTemplate.HasInstanceValues, ref this._frameworkTemplate.ChildRecordFromChildIndex);
                    }
                    if (this.HasLoadedChangeHandler)
                    {
                        BroadcastEventHelper.AddHasLoadedChangeHandlerFlagInAncestry(dependencyObject);
                    }
                }
                else if (this._childName != null)
                {
                    affectedChildren.Add(dependencyObject);
                }
                else
                {
                    if (noChildIndexChildren == null)
                    {
                        noChildIndexChildren = new List <DependencyObject>(4);
                    }
                    noChildIndexChildren.Add(dependencyObject);
                }
                if (container == parent)
                {
                    TemplateNameScope value = new TemplateNameScope(container);
                    NameScope.SetNameScope(dependencyObject, value);
                    if (flag)
                    {
                        frameworkElement.TemplateChild = frameworkObject.FE;
                    }
                    else
                    {
                        FrameworkElementFactory.AddNodeToLogicalTree((FrameworkContentElement)parent, this._type, isFE, frameworkObject.FE, frameworkObject.FCE);
                    }
                }
                else
                {
                    this.AddNodeToParent(parent, frameworkObject);
                }
                if (!flag2)
                {
                    StyleHelper.InvalidatePropertiesOnTemplateNode(container, frameworkObject, this._childIndex, ref this._frameworkTemplate.ChildRecordFromChildIndex, false, this);
                }
                else
                {
                    for (int i = 0; i < this.PropertyValues.Count; i++)
                    {
                        if (this.PropertyValues[i].ValueType != PropertyValueType.Set)
                        {
                            throw new NotSupportedException(SR.Get("Template3DValueOnly", new object[]
                            {
                                this.PropertyValues[i].Property
                            }));
                        }
                        object    obj       = this.PropertyValues[i].ValueInternal;
                        Freezable freezable = obj as Freezable;
                        if (freezable != null && !freezable.CanFreeze)
                        {
                            obj = freezable.Clone();
                        }
                        MarkupExtension markupExtension = obj as MarkupExtension;
                        if (markupExtension != null)
                        {
                            ProvideValueServiceProvider provideValueServiceProvider = new ProvideValueServiceProvider();
                            provideValueServiceProvider.SetData(visual3D, this.PropertyValues[i].Property);
                            obj = markupExtension.ProvideValue(provideValueServiceProvider);
                        }
                        visual3D.SetValue(this.PropertyValues[i].Property, obj);
                    }
                }
                for (FrameworkElementFactory frameworkElementFactory = this._firstChild; frameworkElementFactory != null; frameworkElementFactory = frameworkElementFactory._nextSibling)
                {
                    frameworkElementFactory.InstantiateTree(dataField, container, dependencyObject, affectedChildren, ref noChildIndexChildren, ref resourceDependents);
                }
                if (!flag2)
                {
                    FrameworkElementFactory.NewNodeEndInit(isFE, frameworkObject.FE, frameworkObject.FCE);
                }
            }
            return(dependencyObject);
        }
            public void AddChangedHandler(Freezable resource)
            {
                // If _resource already exists, unhook the event handler.
                if (_resource != null)
                {
                    RemoveChangedHandler();
                }

                _resource = resource;
            
                Debug.Assert(!_resource.IsFrozen);
                _resource.Changed += new EventHandler(this.InvalidateTargetSubProperty);
            }
        /// <summary> 
        /// Implementation of <see cref="System.Windows.Freezable.CloneCurrentValueCore(Freezable)">Freezable.CloneCurrentValueCore</see>.
        /// </summary> 
        protected override void CloneCurrentValueCore(Freezable sourceFreezable)
        {
            QuaternionAnimationUsingKeyFrames sourceAnimation = (QuaternionAnimationUsingKeyFrames) sourceFreezable;
            base.CloneCurrentValueCore(sourceFreezable); 

            CopyCommon(sourceAnimation, /* isCurrentValueClone = */ true); 
        } 
 //
 // Summary:
 //     Makes the instance a frozen clone of the specified System.Windows.Freezable
 //     using base (non-animated) property values.
 //
 // Parameters:
 //   sourceFreezable:
 //     The instance to copy.
 protected virtual void GetAsFrozenCore(Freezable sourceFreezable)
 {
 }
        /// <summary>
        /// Implementation of <see cref="System.Windows.Freezable.CloneCore(System.Windows.Freezable)">Freezable.CloneCore</see>.
        /// </summary>
        protected override void CloneCore(Freezable sourceFreezable)
        {
            CharAnimationUsingKeyFrames sourceAnimation = (CharAnimationUsingKeyFrames) sourceFreezable;
            base.CloneCore(sourceFreezable);

            CopyCommon(sourceAnimation, /* isCurrentValueClone = */ false);
        }
 bool IFreezeFreezables.TryFreeze(string value, Freezable freezable)
 {
     return _context.TryCacheFreezable(value, freezable);
 }
 // The creator of a FreezableDefaultValuePromoter should call this method
 // so that we can verify that the changed sender is the mutable default
 // value we handed out.
 internal void SetFreezableDefaultValue(Freezable mutableDefaultValue)
 {
     _mutableDefaultValue = mutableDefaultValue;
 }
        /// <summary>
        /// Implementation of Freezable.CloneCore()
        /// </summary>
        protected override void CloneCore(Freezable source)
        {
            base.CloneCore(source);

            StreamGeometry sourceStream = (StreamGeometry) source;

            if ((sourceStream._data != null) && (sourceStream._data.Length > 0))
            {
                _data = new byte[sourceStream._data.Length];
                sourceStream._data.CopyTo(_data, 0);
            }
        }
        protected override void CloneCurrentValueCore(Freezable sourceFreezable)
        {
            base.CloneCurrentValueCore(sourceFreezable);

            CloneCommon(sourceFreezable);
        }
        /// <summary>
        /// Implementation of Freezable.GetCurrentValueAsFrozenCore()
        /// </summary>
        protected override void GetCurrentValueAsFrozenCore(Freezable source)
        {
            base.GetCurrentValueAsFrozenCore(source);

            StreamGeometry sourceStream = (StreamGeometry) source;

            if ((sourceStream._data != null) && (sourceStream._data.Length > 0))
            {
                _data = new byte[sourceStream._data.Length];
                sourceStream._data.CopyTo(_data, 0);
            }
        }
        private void CloneCommon(Freezable sourceFreezable)
        {           
            D3DImage source = (D3DImage)sourceFreezable;

            _dpiX = source._dpiX;
            _dpiY = source._dpiY;
            
            Lock();
            // If we've lost the front buffer, _pUserSurface unsafe will be null
            SetBackBuffer(D3DResourceType.IDirect3DSurface9, source._pUserSurfaceUnsafe);
            Unlock();
        }
 /// <summary> 
 /// Implementation of <see cref="System.Windows.Freezable.CloneCurrentValueCore(Freezable)">Freezable.CloneCurrentValueCore</see>.
 /// </summary> 
 /// <param name="sourceFreezable"></param> 
 protected override void CloneCurrentValueCore(Freezable sourceFreezable)
 { 
     GeneralTransform2DTo3DTo2D transform = (GeneralTransform2DTo3DTo2D)sourceFreezable;
     base.CloneCurrentValueCore(sourceFreezable);
     CopyCommon(transform);
 } 
	protected override void CloneCurrentValueCore (Freezable sourceFreezable)
	{
		throw new NotImplementedException ();
	}
 /// <summary>
 /// Implementation of <see cref="System.Windows.Freezable.GetCurrentValueAsFrozenCore(Freezable)">Freezable.GetCurrentValueAsFrozenCore</see>.
 /// </summary>
 /// <param name="sourceFreezable"></param> 
 protected override void GetCurrentValueAsFrozenCore(Freezable sourceFreezable)
 { 
     GeneralTransform2DTo3DTo2D transform = (GeneralTransform2DTo3DTo2D)sourceFreezable; 
     base.GetCurrentValueAsFrozenCore(sourceFreezable);
     CopyCommon(transform); 
 }