コード例 #1
0
 protected IDataDescriptor GetDataDescriptor(UIElement element)
 {
     string targetName = Storyboard.GetTargetName(this);
       object targetObject = null;
       if (targetName == null)
     targetObject = element;
       else
       {
     INameScope ns = element.FindNameScope();
     if (ns != null)
       targetObject = ns.FindName(targetName);
     if (targetObject == null)
       targetObject = element.FindElement(new NameMatcher(targetName));
     if (targetObject == null)
       return null;
       }
       try
       {
     IDataDescriptor result = new ValueDataDescriptor(targetObject);
     if (_propertyExpression != null && _propertyExpression.Evaluate(result, out result))
       return result;
       }
       catch (XamlBindingException e)
       {
     ServiceRegistration.Get<ILogger>().Warn("PropertyAnimationTimeline: Error evaluating expression '{0}' on target object '{1}'", e, _propertyExpression, targetObject);
       }
       return null;
 }
コード例 #2
0
        public T GetElement(object source)
        {
            IDataDescriptor result;

            _compiledPath.Evaluate(new ValueDataDescriptor(source), out result);
            if (result == null)
            {
                return(null);
            }
            return((T)TypeConverter.Convert(result.Value, typeof(T)));
        }
コード例 #3
0
        /// <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 virtual bool UpdateSourceValue()
        {
            bool sourceValueValid = false;

            try
            {
                IDataDescriptor evaluatedValue;
                if (!GetSourceDataDescriptor(out evaluatedValue))
                {
                    // Do nothing if not all necessary properties can be resolved at the current time
                    return(false);
                }
                if (_compiledPath != null)
                {
                    try
                    {
                        if (!_compiledPath.Evaluate(evaluatedValue, out evaluatedValue))
                        {
                            return(false);
                        }
                    }
                    catch (XamlBindingException)
                    {
                        return(false);
                    }
                }
                // If no path is specified, evaluatedValue will be the source value
                IsSourceValueValid = sourceValueValid = true;
                _evaluatedSourceValue.SourceValue = evaluatedValue;
                return(true);
            }
            finally
            {
                IsSourceValueValid = sourceValueValid;
            }
        }