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); MPF.TryCleanupAndDispose(SelectionChanged); }
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; } }
protected ControlTemplate FindKeyboardLayout(CultureInfo culture) { // Try culture specific keyboard layouts object o = FindResourceInTheme(VIRTUAL_KEYBOARD_RESOURCE_PREFIX + '_' + culture.TwoLetterISOLanguageName, false); ControlTemplate result = o as ControlTemplate; if (result != null) { return(result); } if (o != null) { MPF.TryCleanupAndDispose(o); } if (!culture.IsNeutralCulture) { return(FindKeyboardLayout(culture.Parent)); } // Fallback: Take default keyboard o = FindResourceInTheme(VIRTUAL_KEYBOARD_RESOURCE_PREFIX, false); result = o as ControlTemplate; if (result == null && o != null) { MPF.TryCleanupAndDispose(o); } return(result); }
public override void Dispose() { Detach(); MPF.TryCleanupAndDispose(Fill); MPF.TryCleanupAndDispose(Stroke); base.Dispose(); }
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(StarTemplate); MPF.TryCleanupAndDispose(StarReadOnlyTemplate); base.Dispose(); }
protected void TriggerIfValuesEqual(object triggerValue, object checkValue) { object obj = null; try { if (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); } } }
protected void DisposeImageSources() { MPF.TryCleanupAndDispose(_sourceState.ImageSource); _sourceState.ImageSource = null; MPF.TryCleanupAndDispose(_fallbackSourceState.ImageSource); _fallbackSourceState.ImageSource = null; }
public override void Dispose() { FrameworkElement visual = Visual; MPF.TryCleanupAndDispose(visual); base.Dispose(); }
/// <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); }
protected void UpdateTarget(object value) { // We're called multiple times, for example when a resource dictionary changes. // To avoid too many updates, we remember the last updated value. if (ReferenceEquals(value, _lastUpdateValue)) { return; } _lastUpdateValue = value; object assignValue = MpfCopyManager.DeepCopyCutLVPs(value); if (assignValue is DependencyObject && _targetDataDescriptor.TargetObject is DependencyObject) { ((DependencyObject)assignValue).LogicalParent = (DependencyObject)_targetDataDescriptor.TargetObject; } #if DEBUG_DRME DebugOutput("Setting target value to '{0}'", assignValue); #endif object assignValueConverted = TypeConverter.Convert(assignValue, _targetDataDescriptor.DataType); if (!ReferenceEquals(assignValue, assignValueConverted) && !ReferenceEquals(assignValue, value)) { MPF.TryCleanupAndDispose(assignValue); } _contextObject.SetBindingValue(_targetDataDescriptor, assignValueConverted); // If we cannot find any UI element to pass the bindings to, we don't activate them. This means bindings, which are bound to // an object which doesn't have an UI element in its logical tree, cannot be activated. }
public override void Dispose() { base.Dispose(); Detach(); MPF.TryCleanupAndDispose(RelativeTransform); MPF.TryCleanupAndDispose(Transform); }
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(); }
public void Add(KeyValuePair <object, object> item) { IDictionary <object, object> resources = GetOrCreateUnderlayingDictionary(); resources.Add(item); MPF.SetOwner(item.Value, this, false); FireChanged(); }
public override void Dispose() { foreach (object command in _commands) { MPF.TryCleanupAndDispose(command); } 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() { MPF.TryCleanupAndDispose(Value); if (_dataDescriptor != null) { _dataDescriptor.Detach(OnPropertyChanged); } 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 void Clear() { lock (_syncObj) { foreach (object element in _elements) MPF.TryCleanupAndDispose(element); _elements.Clear(); } FireCollectionChanged(); }
internal void Add(object key, object value, bool fireChanged) { IDictionary <object, object> resources = GetOrCreateUnderlayingDictionary(); resources.Add(key, value); MPF.SetOwner(value, this, false); if (fireChanged) { FireChanged(); } }
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() { if (_resources != null) { foreach (object res in _resources.Values) { // Really dispose objects if we are the owner MPF.CleanupAndDisposeResourceIfOwner(res, this); } } base.Dispose(); }
public void Clear() { if (_resources == null) { return; } foreach (KeyValuePair <object, object> kvp in _resources) { MPF.CleanupAndDisposeResourceIfOwner(kvp.Value, this); } _resources = null; FireChanged(); }
public override void Dispose() { foreach (SetterBase setterBase in _setters) { setterBase.Dispose(); } foreach (TriggerBase triggerBase in Triggers) { triggerBase.Dispose(); } MPF.TryCleanupAndDispose(_resources); base.Dispose(); }
/// <summary> /// Takes over the control over the resources in the given resource dictionary. That means, the /// <see cref="DependencyObject.LogicalParent"/> properties of the resource keys and values will be set to this /// instance. /// </summary> /// <param name="dict">Resource dictionary whose contents should be taken over.</param> /// <param name="overwriteNames">If set to <c>true</c>, name collisions between the <paramref name="dict"/> and /// this dictionary will be ignored.</param> /// <param name="takeoverDictInstance">If set to <c>true</c>, the given <paramref name="dict"/> instance will be /// disposed by this method. Else, the <paramref name="dict"/> will be left untouched.</param> public void TakeOver(ResourceDictionary dict, bool overwriteNames, bool takeoverDictInstance) { bool wasChanged = false; foreach (KeyValuePair <object, object> entry in (IDictionary <object, object>)dict) { object key = entry.Key; object value = entry.Value; Set(key, value, false); // Here we have the rare case that we must force to set the owner property to this instance to make the adopted resource really // belong to it. MPF.SetOwner(value, this, true); DependencyObject depObj = key as DependencyObject; if (depObj != null) { depObj.LogicalParent = this; } depObj = value as DependencyObject; if (depObj != null) { depObj.LogicalParent = this; } wasChanged = true; } if (dict._names != null) { foreach (KeyValuePair <string, object> kvp in dict._names) { if (overwriteNames) { SetName(kvp.Key, kvp.Value); } else { RegisterName(kvp.Key, kvp.Value); } } } if (takeoverDictInstance) { if (dict._resources != null) { dict._resources.Clear(); } dict.Dispose(); } if (wasChanged) { FireChanged(); } }
/// <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; } }
internal void Set(object key, object value, bool fireChanged) { IDictionary <object, object> resources = GetOrCreateUnderlayingDictionary(); object oldRes; if (resources.TryGetValue(key, out oldRes)) { MPF.CleanupAndDisposeResourceIfOwner(oldRes, this); } resources[key] = value; MPF.SetOwner(value, this, false); if (fireChanged) { FireChanged(); } }