Esempio n. 1
0
 public override void Dispose()
 {
     Detach();
     MPF.TryCleanupAndDispose(StarTemplate);
     MPF.TryCleanupAndDispose(StarReadOnlyTemplate);
     base.Dispose();
 }
Esempio n. 2
0
        public override void Dispose()
        {
            FrameworkElement visual = Visual;

            MPF.TryCleanupAndDispose(visual);
            base.Dispose();
        }
Esempio n. 3
0
        protected void TriggerIfValuesEqual(object triggerValue, object checkValue)
        {
            object obj = null;

            try
            {
                if ((triggerValue == null && checkValue == null) || (triggerValue != null && TypeConverter.Convert(checkValue, triggerValue.GetType(), out obj) &&
                                                                     Equals(triggerValue, obj)))
                {
                    ExecuteTriggerStartActions();
                }
                else
                {
                    ExecuteTriggerEndActions();
                }
            }
            finally
            {
                if (!ReferenceEquals(obj, checkValue))
                {
                    // If the conversion created a copy of the object, dispose it
                    MPF.TryCleanupAndDispose(obj);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes the <see cref="ItemsControl.ItemsSource"/> property with the <see cref="SubItemsProvider"/>.
        /// </summary>
        /// <returns><c>true</c>, if the <see cref="ItemsControl.ItemsSource"/> property was changed by this method, else <c>false</c>.</returns>
        protected virtual bool InitializeSubItemsSource()
        {
            SubItemsProvider sip            = SubItemsProvider;
            IEnumerable      oldItemsSource = ItemsSource;

            if (!_contextChangedAttached)
            {
                ContextChanged         += OnContextChanged;
                _contextChangedAttached = true;
            }
            if (_attachedContextSource != null)
            {
                _attachedContextSource.Detach(OnDataContextValueChanged);
            }
            _attachedContextSource = DataContext.EvaluatedSourceValue;
            _attachedContextSource.Attach(OnDataContextValueChanged);
            object context = Context;

            if (context == null)
            {
                return(false);
            }
            ItemsSource = sip == null ? null : sip.GetSubItems(context);
            if (oldItemsSource == ItemsSource)
            {
                return(false);
            }
            MPF.TryCleanupAndDispose(oldItemsSource);
            CheckExpandable();
            return(true);
        }
Esempio n. 5
0
        public override void Dispose()
        {
            Detach();
            DetachFromItemsSource(ItemsSource);
            ItemCollection items = _items;

            if (items != null)
            {
                DetachFromItems(items);
                items.Dispose();
            }
            ItemCollection preparedItems = _preparedItems;

            if (preparedItems != null)
            {
                preparedItems.Dispose();
            }
            ItemCollection preparedChildren = _preparedChildren;

            if (preparedChildren != null)
            {
                preparedChildren.Dispose();
            }
            base.Dispose();
            MPF.TryCleanupAndDispose(ItemTemplate);
            MPF.TryCleanupAndDispose(ItemContainerStyle);
            MPF.TryCleanupAndDispose(ItemsPanel);
        }
Esempio n. 6
0
        internal void OnContentChanged(AbstractProperty prop, object oldValue)
        {
            object content = Content;

            MPF.TryCleanupAndDispose(oldValue);
            if (!ReferenceEquals(oldValue, _convertedContent))
            {
                MPF.TryCleanupAndDispose(_convertedContent);
            }

            object convertedContent;

            // Try to unwrap ResourceWrapper before _convertedContent is accessed elsewhere.
            // That's the only function we need from the ConvertType method, that's why we only call MPF.ConvertType
            // instead of TypeConverter.Convert.
            if (!MPF.ConvertType(content, typeof(object), out convertedContent))
            {
                convertedContent = content;
            }

            _convertedContent = ReferenceEquals(content, convertedContent) ? MpfCopyManager.DeepCopySetLVPs(convertedContent, this, this) : convertedContent;

            if (ContentTemplate == null)
            {
                // No ContentTemplate set
                InstallAutomaticContentDataTemplate();
            }
            FrameworkElement templateControl = _templateControl;

            if (!(_convertedContent is FrameworkElement) && templateControl != null) // If our content is a FrameworkElement itself, it should only be used as template control but not as context
            // The controls in the DataTemplate access their "data" via their data context, so we must assign it
            {
                templateControl.Context = _convertedContent;
            }
        }
Esempio n. 7
0
        void OnTemplateControlChanged(AbstractProperty property, object oldValue)
        {
            FrameworkElement oldTemplateControl = oldValue as FrameworkElement;

            MPF.TryCleanupAndDispose(oldTemplateControl);

            FrameworkElement element = TemplateControl;

            if (element != null)
            {
                element.VisualParent = this;
                element.SetScreen(Screen);
                element.SetElementState(_elementState);
                if (element.TemplateNameScope == null)
                {
                    // This might be the case if the TemplateControl is directly assigned, without the use of a FrameworkTemplate,
                    // which normally sets the TemplateNameScope.
                    element.TemplateNameScope = new NameScope();
                }
                if (IsAllocated)
                {
                    element.Allocate();
                }
            }
            _initializedTemplateControl = element;
            InvalidateLayout(true, true);
        }
Esempio n. 8
0
 public override void Dispose()
 {
     Detach();
     MPF.TryCleanupAndDispose(Fill);
     MPF.TryCleanupAndDispose(Stroke);
     base.Dispose();
 }
Esempio n. 9
0
 protected void DisposeImageSources()
 {
     MPF.TryCleanupAndDispose(_sourceState.ImageSource);
     _sourceState.ImageSource = null;
     MPF.TryCleanupAndDispose(_fallbackSourceState.ImageSource);
     _fallbackSourceState.ImageSource = null;
 }
 public override void Dispose()
 {
     MPF.TryCleanupAndDispose(_convertedContent);
     MPF.TryCleanupAndDispose(_templateControl);
     MPF.TryCleanupAndDispose(Content);
     MPF.TryCleanupAndDispose(ContentTemplate);
     base.Dispose();
 }
Esempio n. 11
0
 public override void Dispose()
 {
     MPF.TryCleanupAndDispose(Template);
     MPF.TryCleanupAndDispose(TemplateControl);
     MPF.TryCleanupAndDispose(BorderBrush);
     MPF.TryCleanupAndDispose(Background);
     base.Dispose();
 }
Esempio n. 12
0
        protected IList <FrameworkElement> _materializedItems = null; // Same size as _items, only parts are populated

        public void Dispose()
        {
            DisposeItems();
            MPF.TryCleanupAndDispose(_itemTemplate);
            _itemTemplate = null;
            MPF.TryCleanupAndDispose(_itemContainerStyle);
            _itemContainerStyle = null;
        }
Esempio n. 13
0
 public override void Dispose()
 {
     foreach (object command in _commands)
     {
         MPF.TryCleanupAndDispose(command);
     }
     base.Dispose();
 }
Esempio n. 14
0
 public override void Dispose()
 {
     MPF.TryCleanupAndDispose(CommandStencil);
     foreach (object parameter in CommandParameters)
     {
         MPF.TryCleanupAndDispose(parameter);
     }
     base.Dispose();
 }
Esempio n. 15
0
 public override void Dispose()
 {
     Detach();
     StopTimer();
     UnsubscribeFromMessages();
     MPF.TryCleanupAndDispose(HeaderTemplate);
     MPF.TryCleanupAndDispose(ProgramTemplate);
     base.Dispose();
 }
Esempio n. 16
0
 public override void Dispose()
 {
     MPF.TryCleanupAndDispose(Value);
     if (_dataDescriptor != null)
     {
         _dataDescriptor.Detach(OnPropertyChanged);
     }
     base.Dispose();
 }
Esempio n. 17
0
 public void Clear()
 {
   lock (_syncObj)
   {
     foreach (object element in _elements)
       MPF.TryCleanupAndDispose(element);
     _elements.Clear();
   }
   FireCollectionChanged();
 }
Esempio n. 18
0
 public void Dispose()
 {
     foreach (object value in _valuesToSet.Values)
     {
         MPF.TryCleanupAndDispose(value);
     }
     // 2011-09-10 Albert TODO: Proper disposal of animation contexts. Not necessary at the moment because currently,
     // no animation can cope with disposable objects. As soon as there are such animations, disposal should be implemented for AnimationContexts.
     //foreach (AnimationContext context in _scheduledAnimations)
     //  context.Dispose();
 }
Esempio n. 19
0
 public bool Remove(object element)
 {
   bool result;
   lock (_syncObj)
   {
     result = _elements.Remove(element);
     MPF.TryCleanupAndDispose(element);
   }
   FireCollectionChanged();
   return result;
 }
Esempio n. 20
0
 public override void Dispose()
 {
     foreach (SetterBase setterBase in _setters)
     {
         setterBase.Dispose();
     }
     foreach (TriggerBase triggerBase in Triggers)
     {
         triggerBase.Dispose();
     }
     MPF.TryCleanupAndDispose(_resources);
     base.Dispose();
 }
        /// <summary>
        /// Will be called to evaluate our source value based on all available
        /// property and context states.
        /// This method will also be automatically re-called when any object involved in the
        /// evaluation process of our source value was changed.
        /// </summary>
        /// <returns><c>true</c>, if the source value based on all input data
        /// could be evaluated, else <c>false</c>.</returns>
        protected bool UpdateSourceValue()
        {
            if (_isUpdatingSourceValue)
            {
                return(false);
            }
            _isUpdatingSourceValue = true;
            bool sourceValueValid = false;

            try
            {
                object result;
                bool   copy = false;
                lock (_syncObj)
                {
                    IDataDescriptor[] values;
                    if (!GetSourceValues(out values))
                    {
                        // Do nothing if not all necessary child bindings can be resolved at the current time
                        return(false);
                    }
                    if (_converter == null)
                    {
                        throw new XamlBindingException("MultiBindingMarkupExtension: Converter must be set");
                    }
                    Type targetType = _targetDataDescriptor == null ? typeof(object) : _targetDataDescriptor.DataType;
                    if (!_converter.Convert(values, targetType, ConverterParameter, out result))
                    {
                        return(false);
                    }
                    copy = values.Any(dd => dd != null && ReferenceEquals(dd.Value, result));
                    IsSourceValueValid = sourceValueValid = true;
                }
                object oldValue = _evaluatedSourceValue.SourceValue;
                // Set the binding's value outside the lock to comply with the MP2 threading policy
                _evaluatedSourceValue.SourceValue = new ValueDataDescriptor(copy ? MpfCopyManager.DeepCopyCutLVPs(result) : result);
                if (oldValue != null)
                {
                    MPF.TryCleanupAndDispose(oldValue);
                }
                return(true);
            }
            finally
            {
                IsSourceValueValid     = sourceValueValid;
                _isUpdatingSourceValue = false;
            }
        }
Esempio n. 22
0
        public override void Dispose()
        {
            base.Dispose();
            IItemProvider itemProvider = _itemProvider;

            _itemProvider = null;
            if (itemProvider != null)
            {
                MPF.TryCleanupAndDispose(itemProvider);
            }
            itemProvider     = _newItemProvider;
            _newItemProvider = null;
            if (itemProvider != null)
            {
                MPF.TryCleanupAndDispose(itemProvider);
            }
        }
Esempio n. 23
0
        protected void ResetTriggers(UIElement element)
        {
            element.UninitializeTriggers();
            ICollection <TriggerBase> triggers = element.GetAttachedPropertyValue <ICollection <TriggerBase> >(STYLE_TRIGGERS_ATTACHED_PROPERTY_NAME, null);

            if (triggers != null)
            {
                foreach (TriggerBase trigger in triggers)
                {
                    if (element.Triggers.Remove(trigger))
                    {
                        MPF.TryCleanupAndDispose(trigger);
                    }
                }
                element.SetAttachedPropertyValue <ICollection <TriggerBase> >(STYLE_TRIGGERS_ATTACHED_PROPERTY_NAME, null);
            }
        }
Esempio n. 24
0
 public void SetItemProvider(IItemProvider itemProvider)
 {
     if (_elementState == ElementState.Running)
     {
         lock (Children.SyncRoot)
         {
             if (_newItemProvider == itemProvider)
             {
                 return;
             }
             if (_newItemProvider != null)
             {
                 MPF.TryCleanupAndDispose(_newItemProvider);
             }
             _newItemProvider = null;
             if (_itemProvider == itemProvider)
             {
                 return;
             }
             _newItemProvider = itemProvider;
         }
     }
     else
     {
         if (_newItemProvider == itemProvider)
         {
             return;
         }
         if (_newItemProvider != null)
         {
             MPF.TryCleanupAndDispose(_newItemProvider);
         }
         _newItemProvider = null;
         if (_itemProvider == itemProvider)
         {
             return;
         }
         if (_itemProvider != null)
         {
             MPF.TryCleanupAndDispose(_itemProvider);
         }
         _itemProvider = itemProvider;
     }
     InvalidateLayout(true, true);
 }
Esempio n. 25
0
        protected void TriggerIfValuesEqual(object triggerValue, object checkValue)
        {
            object obj = null;

            try
            {
                Triggered = triggerValue != null && TypeConverter.Convert(checkValue, triggerValue.GetType(), out obj) &&
                            Equals(triggerValue, obj);
            }
            finally
            {
                if (!ReferenceEquals(obj, checkValue))
                {
                    // If the conversion created a copy of the object, dispose it
                    MPF.TryCleanupAndDispose(obj);
                }
            }
        }
Esempio n. 26
0
 public override void Dispose()
 {
     base.Dispose();
     foreach (UIElement child in GetChildren())
     {
         child.StopAndDispose();
     }
     foreach (TriggerBase triggerBase in Triggers)
     {
         triggerBase.Dispose();
     }
     MPF.TryCleanupAndDispose(RenderTransform);
     MPF.TryCleanupAndDispose(LayoutTransform);
     MPF.TryCleanupAndDispose(Effect);
     MPF.TryCleanupAndDispose(TemplateNameScope);
     MPF.TryCleanupAndDispose(OpacityMask);
     MPF.TryCleanupAndDispose(_resources);
 }
Esempio n. 27
0
        protected override SizeF CalculateInnerDesiredSize(SizeF totalSize)
        {
            FrameworkElementCollection children = Children;

            lock (Children.SyncRoot)
            {
                if (_newItemProvider != null)
                {
                    if (children.Count > 0)
                    {
                        children.Clear(false);
                    }
                    if (_itemProvider != null)
                    {
                        MPF.TryCleanupAndDispose(_itemProvider);
                    }
                    _itemProvider      = _newItemProvider;
                    _newItemProvider   = null;
                    _updateRenderOrder = true;
                }
                _assumedLineExtendsInNonOrientationDirection = 0;
                IItemProvider itemProvider = ItemProvider;
                if (itemProvider == null)
                {
                    return(base.CalculateInnerDesiredSize(totalSize));
                }
                int numItems = itemProvider.NumItems;
                if (numItems == 0)
                {
                    return(new SizeF());
                }

                // CalculateInnerDesiredSize is called before ArrangeChildren!
                // under the precondition that all items use the same template and are equally sized
                // calulate just one line to find number of items and required size of a line
                LineMeasurement exemplaryLine = _firstArrangedLineIndex < 0 ? CalculateLine(0, totalSize, false) : _arrangedLines[_firstArrangedLineIndex];
                _assumedLineExtendsInNonOrientationDirection = exemplaryLine.TotalExtendsInNonOrientationDirection;
                var itemsPerLine = exemplaryLine.EndIndex - exemplaryLine.StartIndex + 1;
                var estimatedExtendsInNonOrientationDirection = (float)Math.Ceiling((float)numItems / itemsPerLine) * _assumedLineExtendsInNonOrientationDirection;

                return(Orientation == Orientation.Horizontal ? new SizeF(exemplaryLine.TotalExtendsInOrientationDirection, estimatedExtendsInNonOrientationDirection) :
                       new SizeF(estimatedExtendsInNonOrientationDirection, exemplaryLine.TotalExtendsInOrientationDirection));
            }
        }
Esempio n. 28
0
        protected void LoadStyleResource(string resourceKey, bool searchInheritedResources)
        {
            PendingResource pr;

            if (_pendingStyleResources.TryGetValue(resourceKey, out pr))
            {
                if (pr.State != LoadState.Loading)
                {
                    pr.State = LoadState.Loading;
                    ILogger logger = ServiceRegistration.Get <ILogger>();
                    try
                    {
                        logger.Info("SkinResources: Loading style resource '{0}' from file '{1}'", resourceKey, pr.ResourcePath);
                        object             o  = XamlLoader.Load(pr.ResourcePath, this, new StyleResourceModelLoader(this));
                        ResourceDictionary rd = o as ResourceDictionary;
                        if (rd == null)
                        {
                            if (o != null)
                            {
                                MPF.TryCleanupAndDispose(o);
                            }
                            throw new InvalidCastException("Style resource file '" + pr.ResourcePath + "' doesn't contain a ResourceDictionary as root element");
                        }
                        _localStyleResources.TakeOver(rd, false, true);
                    }
                    catch (Exception ex)
                    {
                        _pendingStyleResources.Clear();
                        throw new EnvironmentException("Error loading style resource '{0}'", ex, pr.ResourcePath);
                    }
                    finally
                    {
                        _pendingStyleResources.Remove(resourceKey);
                    }
                }
            }
            // Search in inherited resources after we searched through our own resources to make it possible to
            // override style resources in a file with the same name (in that case, the current file from our own resource collection
            // will be loaded first and thus is able to insert an overridden style before the inherited resource file is loaded).
            if (searchInheritedResources && _inheritedSkinResources != null)
            {
                _inheritedSkinResources.LoadStyleResource(resourceKey, true);
            }
        }
Esempio n. 29
0
 public void Initialize(FrameworkElement parent, IEnumerable <object> itemsSource, Style itemContainerStyle, DataTemplate itemTemplate)
 {
     _parent = parent;
     if (_materializedItems != null)
     {
         DisposeItems();
     }
     _items             = new List <object>(itemsSource);
     _materializedItems = new List <FrameworkElement>(_items.Count);
     for (int i = 0; i < _items.Count; i++)
     {
         _materializedItems.Add(null);
     }
     MPF.TryCleanupAndDispose(_itemContainerStyle);
     MPF.TryCleanupAndDispose(_itemTemplate);
     // No need to set the LogicalParent at styles or data templates because they don't bind bindings
     _itemContainerStyle = MpfCopyManager.DeepCopyCutLVPs(itemContainerStyle);
     _itemTemplate       = MpfCopyManager.DeepCopyCutLVPs(itemTemplate);
 }
Esempio n. 30
0
        public void Execute()
        {
            IList <object> convertedCommands = LateBoundValue.ConvertLateBoundValues(_commands);

            foreach (object objectCmd in convertedCommands)
            {
                object o;
                if (!TypeConverter.Convert(objectCmd, typeof(IExecutableCommand), out o))
                {
                    throw new ArgumentException(string.Format("CommandList: Command '{0}' cannot be converted to {1}", objectCmd, typeof(IExecutableCommand).Name));
                }
                IExecutableCommand cmd = (IExecutableCommand)o;
                cmd.Execute();
                if (!ReferenceEquals(cmd, objectCmd))
                {
                    MPF.TryCleanupAndDispose(cmd);
                }
            }
        }