public override void Dispose() { Detach(); MPF.TryCleanupAndDispose(StarTemplate); MPF.TryCleanupAndDispose(StarReadOnlyTemplate); base.Dispose(); }
public override void Dispose() { FrameworkElement visual = Visual; MPF.TryCleanupAndDispose(visual); base.Dispose(); }
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); } } }
/// <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); }
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); }
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; } }
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); }
public override void Dispose() { Detach(); MPF.TryCleanupAndDispose(Fill); MPF.TryCleanupAndDispose(Stroke); base.Dispose(); }
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(); }
public override void Dispose() { MPF.TryCleanupAndDispose(Template); MPF.TryCleanupAndDispose(TemplateControl); MPF.TryCleanupAndDispose(BorderBrush); MPF.TryCleanupAndDispose(Background); base.Dispose(); }
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; }
public override void Dispose() { foreach (object command in _commands) { MPF.TryCleanupAndDispose(command); } base.Dispose(); }
public override void Dispose() { MPF.TryCleanupAndDispose(CommandStencil); foreach (object parameter in CommandParameters) { MPF.TryCleanupAndDispose(parameter); } base.Dispose(); }
public override void Dispose() { Detach(); StopTimer(); UnsubscribeFromMessages(); MPF.TryCleanupAndDispose(HeaderTemplate); MPF.TryCleanupAndDispose(ProgramTemplate); base.Dispose(); }
public override void Dispose() { MPF.TryCleanupAndDispose(Value); if (_dataDescriptor != null) { _dataDescriptor.Detach(OnPropertyChanged); } base.Dispose(); }
public void Clear() { lock (_syncObj) { foreach (object element in _elements) MPF.TryCleanupAndDispose(element); _elements.Clear(); } FireCollectionChanged(); }
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(); }
public bool Remove(object element) { bool result; lock (_syncObj) { result = _elements.Remove(element); MPF.TryCleanupAndDispose(element); } FireCollectionChanged(); return result; }
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; } }
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); } }
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); } }
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); }
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); } } }
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); }
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)); } }
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); } }
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); }
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); } } }