/// <summary> /// Called once per iteration through the FrugalMap containing all cached default values /// for a given DependencyObject. This method removes the promotion handlers on each cached /// default and freezes it. /// </summary> /// <param name="list"></param> /// <param name="key">The DP's global index</param> /// <param name="value">The cached default</param> private static void DefaultValueCacheRemovalCallback(ArrayList list, int key, object value) { Freezable cachedDefault = value as Freezable; if (cachedDefault != null) { // Freeze fires the Changed event so we need to clear off the handlers before // calling it. Otherwise the promoter would run and attempt to set the // cached default as a local value. cachedDefault.ClearContextAndHandlers(); cachedDefault.Freeze(); } }
/// <summary> /// Implementation of <see cref="System.Windows.Freezable.FreezeCore">Freezable.FreezeCore</see>. /// </summary> protected override bool FreezeCore(bool isChecking) { bool canFreeze = base.FreezeCore(isChecking); int count = _collection.Count; for (int i = 0; i < count && canFreeze; i++) { canFreeze &= Freezable.Freeze(_collection[i], isChecking); } return(canFreeze); }
/// <summary> /// Implementation of <see cref="System.Windows.Freezable.FreezeCore">Freezable.FreezeCore</see>. /// </summary> protected override bool FreezeCore(bool isChecking) { bool canFreeze = base.FreezeCore(isChecking); int count = _collection.Count; for (int i = 0; i < count && canFreeze; i++) { T item = _collection[i]; Freezable itemAsFreezable = item as Freezable; if (itemAsFreezable != null) { canFreeze &= Freezable.Freeze(itemAsFreezable, isChecking); } else { canFreeze &= (item.Dispatcher == null); } } return(canFreeze); }
/// <summary> /// Try to freeze object /// </summary> /// <param name="freezable">Freezable object</param> /// <returns></returns> public static Boolean TryFreeze(Freezable freezable) { Debug.Assert(freezable != null); if (freezable.CanFreeze) { freezable.Freeze(); return true; }else return false; }
/// <summary> /// Helper method that just invokes Freeze on provided /// Freezable if it's not null. Otherwise it doesn't do anything. /// </summary> /// <param name="freezable">Freezable to freeze.</param> /// <param name="isChecking">If this is true, the method will just check /// to see that the object can be frozen, but won't actually freeze it. /// </param> /// <returns>True if the Freezable was or can be frozen. /// False if isChecking was true and the Freezable can't be frozen. /// </returns> /// <exception cref="System.InvalidOperationException">This exception /// will be thrown if isChecking is passed in as false and this /// Freezable can't be frozen.</exception> // static protected internal bool Freeze(Freezable freezable, bool isChecking) { if (freezable != null) { return freezable.Freeze(isChecking); } // <mcalkins> I guess something that's null is always frozen. return true; }
FreezeIfFreezable ( Freezable freezable ) { Debug.Assert(freezable != null); if (freezable.CanFreeze) { freezable.Freeze(); return (true); } return (false); }
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> /// Freezes the given freezable if the fFreeze flag is true. Used by /// the various drawing methods to freeze resources if there is no /// chance the user might attempt to mutate it. /// (i.e., there are no animations and the dependant properties are /// null or themselves frozen.) /// </summary> private Freezable SetupNewFreezable(Freezable newFreezable, bool fFreeze) { if (fFreeze) { newFreezable.Freeze(); } return newFreezable; }