예제 #1
0
        /// <summary>
        /// Unloads dependency properties.
        /// </summary>
        protected void UnloadDependencyProperties()
        {
            var template = _template;

            while (true)
            {
                List <DependencyProperty> dependencyProperties;
                if (DependencyProperties.TryGetValue(template, out dependencyProperties))
                {
                    // iterate through all dependency properties and clear run-time values
                    for (int i = 0; i < dependencyProperties.Count; ++i)
                    {
                        dependencyProperties[i].Unload(this);
                    }
                }

                // do the same for properties in base class
                template = template.BasedOn;
                if (template == ViewTemplates.Default)
                {
                    break;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Gets list of state changing properties.
        /// </summary>
        private List <DependencyProperty> GetStateChangingProperties(string newState)
        {
            // get list of properties changing state for this template
            List <DependencyProperty> stateChangingProperties;

            if (!StateChangingProperties.TryGetValue(_template, out stateChangingProperties))
            {
                List <DependencyProperty> templateStateChangingProperties = null;

                // initialize list of all properties that changes state for this template
                var template = _template;
                while (true)
                {
                    if (DependencyProperties.TryGetValue(template, out var dependencyProperties))
                    {
                        // iterate through all dependency properties and check if it has state
                        for (int i = 0; i < dependencyProperties.Count; ++i)
                        {
                            var dependencyProperty = dependencyProperties[i];
                            if (dependencyProperty.HasState(_template))
                            {
                                if (templateStateChangingProperties == null)
                                {
                                    templateStateChangingProperties = new List <DependencyProperty>();
                                }

                                templateStateChangingProperties.Add(dependencyProperties[i]);
                            }
                        }
                    }

                    // do the same for properties in base class
                    template = template.BasedOn;
                    if (template == ViewTemplates.Default)
                    {
                        break;
                    }
                }

                stateChangingProperties = templateStateChangingProperties;
                StateChangingProperties.Add(_template, stateChangingProperties);
            }

            if (stateChangingProperties == null)
            {
                return(null);
            }

            // filter properties and return those affected by the state change
            var filteredStateChangingProperties = new List <DependencyProperty>();

            for (int i = 0; i < stateChangingProperties.Count; ++i)
            {
                var property = stateChangingProperties[i];
                if (!property.HasState(_template, _previousState) && !property.HasState(_template, newState))
                {
                    continue;
                }

                filteredStateChangingProperties.Add(stateChangingProperties[i]);
            }

            return(filteredStateChangingProperties);
        }