Ejemplo n.º 1
0
        public static void AddAnimation <T, TValue>(this Storyboard storyboard, Timeline animation, T target, Expression <Func <T, TValue> > targetProperty)
            where T : DependencyObject
        {
            Storyboard.SetTarget(animation, target);

            var propertyPath = PropertyPathGenerator.CreatePropertyPath(targetProperty);

            Storyboard.SetTargetProperty(animation, propertyPath);

            storyboard.Children.Add(animation);
        }
Ejemplo n.º 2
0
        public static PropertyPath CreatePropertyPath <T, TValue>(Expression <Func <T, TValue> > expression)
            where T : DependencyObject
        {
            var generator = new PropertyPathGenerator();

            generator.Visit(expression);

            var builder = new StringBuilder();

            foreach (var token in ((IEnumerable <IToken>)generator.tokens).Reverse())
            {
                if (token is MemberToken && builder.Length > 0)
                {
                    builder.Append('.');
                }
                builder.Append(token.ToString());
            }
            return(new PropertyPath(builder.ToString()));
        }