/// 
        /// <summary>
        /// Helper to create double animation</summary>
        /// 
        public static Storyboard AddDouble(
            this Storyboard                             sb,
            int                                         durationMs,
            DependencyObject                            element,
            PropertyPath                                path,
            double                                      from,
            double                                      to,
            IEasingFunction                             easing = null
        )
        {
            DoubleAnimation                             da;

            da = new DoubleAnimation();
            da.Duration = new Duration(TimeSpan.FromMilliseconds(durationMs));

            da.From = from;
            da.To =  to;

            if (easing != null)
            {
                da.EasingFunction = easing;
            }

            Storyboard.SetTarget(da, element);
            Storyboard.SetTargetProperty(da, path);

            sb.Children.Add(da);
            return sb;
        }
示例#2
0
		public void PropertyPathCtors ()
		{
			PropertyPath prop;
			
			Assert.Throws <ArgumentOutOfRangeException>(() =>
				prop = new PropertyPath ("first", "second")
			, "#1");
			
			Assert.Throws<ArgumentOutOfRangeException>(delegate {
				prop = new PropertyPath (null, "arg1");
			}, "null path throws ArgumentOutOfRangeException");
			
			prop = new PropertyPath (Rectangle.WidthProperty);
			Assert.AreEqual ("(0)", prop.Path, "Normal PropertyPath");
			
			prop = new PropertyPath (Canvas.LeftProperty);
			Assert.AreEqual ("(0)", prop.Path, "Attached PropertyPath");
			
			prop = new PropertyPath (5);
			Assert.IsNull (prop.Path, "numeric PropertyPath is null");

			Assert.Throws<NullReferenceException> (delegate {
				prop = new PropertyPath (null, null);
			}, "Both null");

			Assert.Throws<NullReferenceException> (delegate {
				prop = new PropertyPath ("pathstring", null);
			}, "second null");

			prop = new PropertyPath ((string) null);
			Assert.IsNull (prop.Path, "null PropertyPath is null");
		}
        public static Task SmoothSetAsync(this FrameworkElement @this, DependencyProperty dp, double targetvalue,
            TimeSpan iDuration, CancellationToken iCancellationToken)
        {
            TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
            DoubleAnimation anim = new DoubleAnimation(targetvalue, new Duration(iDuration));
            PropertyPath p = new PropertyPath("(0)", dp);
            Storyboard.SetTargetProperty(anim, p);
            Storyboard sb = new Storyboard();
            sb.Children.Add(anim);
            EventHandler handler = null;
            handler = delegate
            {
                sb.Completed -= handler;
                sb.Remove(@this);
                @this.SetValue(dp, targetvalue);
                tcs.TrySetResult(null);
            };
            sb.Completed += handler;
            sb.Begin(@this, true);

            iCancellationToken.Register(() =>
            {
                double v = (double)@this.GetValue(dp);  
                sb.Stop(); 
                sb.Remove(@this); 
                @this.SetValue(dp, v);
                tcs.TrySetCanceled();
            });

            return tcs.Task;
        }
示例#4
0
 private static Type GetTypeFromName (PropertyPath propertyPath, string name)
 {
     // HACK
     return (Type)typeof(PropertyPath)
         .GetMethod("GetTypeFromName", BindingFlags.Instance | BindingFlags.NonPublic)
         .Invoke(propertyPath, new object[] { name, null });
 }
示例#5
0
        public static Storyboard CreateAnim(DependencyObject target, EquationType type, TimeSpan duration, PropertyPath property, double from, double to)
        {
            Storyboard sb = new Storyboard();

            AddAnimation(sb, target, property, duration, type, from, to);

            return sb;
        }
示例#6
0
 public AnimationInfo(DependencyObject target, PropertyPath propertyPath, double startValue, double endValue, IEasingFunction easingFunction = null)
 {
     Target = target;
       PropertyPath = propertyPath;
       StartValue = startValue;
       EndValue = endValue;
       EasingFunction = easingFunction;
 }
		public virtual Boolean CanCreateCommand( PropertyPath path, DependencyObject target )
		{
			if ( DesignTimeHelper.GetIsInDesignMode() )
			{
				return false;
			}

			return path != null && ( target is FrameworkElement || target is FrameworkContentElement );
		}
 internal static PropertyPath GetPath(DependencyProperty property)
 {
     PropertyPath path;
     if (!PropertyPaths.TryGetValue(property, out path))
     {
         path = new PropertyPath(property);
         PropertyPaths[property] = path;
     }
     return path;
 }
 internal static PropertyPath GetPath(int index)
 {
     PropertyPath path;
     if (!IndexPaths.TryGetValue(index, out path))
     {
         path = new PropertyPath(string.Format("[{0}]", index));
         IndexPaths[index] = path;
     }
     return path;
 }
示例#10
0
 internal static PropertyPath GetPath(string path)
 {
     PropertyPath propertyPath;
     if (!PropertyPaths.TryGetValue(path, out propertyPath))
     {
         propertyPath = new PropertyPath(path);
         PropertyPaths[path] = propertyPath;
     }
     return propertyPath;
 }
示例#11
0
        internal static PropertyPath GetPath(int index)
        {
            PropertyPath path;
            if (!IndexPaths.TryGetValue(index, out path))
            {
                path = new PropertyPath($"[{index}]");
                IndexPaths[index] = path;
            }

            return path;
        }
        public LocBindingTarget(LocalizationInstance loc, FrameworkElement targetObject, PropertyPath path)
        {
            _locInstance = loc;
            _lbCollection.Add(this);
            _path = path;
            
            
            targetObject.DataContextChanged += new DependencyPropertyChangedEventHandler(update_binding);

            update_binding(targetObject, new DependencyPropertyChangedEventArgs(FrameworkElement.DataContextProperty, null, targetObject.DataContext));

        }
示例#13
0
		public void SetName ()
		{
			Storyboard sb = new Storyboard ();
			PropertyPath path = new PropertyPath ("Width");
			Storyboard.SetTargetProperty (sb, path);
			PropertyPath native = Storyboard.GetTargetProperty (sb);

			Assert.AreNotEqual (path, native, "#1");
			Assert.IsFalse (path == native, "#2");
			Assert.AreEqual(path.Path, native.Path, "#3");
			Assert.AreEqual (path.Path, "Width", "#4");
		}
示例#14
0
        PropertyPath PrepareXmlBinding(PropertyPath path)
        {
            if (path == null)
            {
                DependencyProperty targetDP = TargetProperty;
                Type targetType = targetDP.PropertyType;
                string pathString;

                if (targetType == typeof(Object))
                {
                    if (targetDP == System.Windows.Data.BindingExpression.NoTargetProperty ||
                        targetDP == System.Windows.Controls.Primitives.Selector.SelectedValueProperty ||
                        targetDP.OwnerType == typeof(LiveShapingList)
                        )
                    {
                        // these properties want the "value" - i.e. the text of
                        // the first (and usually only) XmlNode
                        pathString = "/InnerText";
                    }
                    else if (targetDP == FrameworkElement.DataContextProperty ||
                              targetDP == CollectionViewSource.SourceProperty)
                    {
                        // these properties want the entire collection
                        pathString = String.Empty;
                    }
                    else
                    {
                        // most object-valued properties want the (current) XmlNode itself
                        pathString = "/";
                    }
                }
                else if (targetType.IsAssignableFrom(typeof(XmlDataCollection)))
                {
                    // these properties want the entire collection
                    pathString = String.Empty;
                }
                else
                {
                    // most other properties want the "value"
                    pathString = "/InnerText";
                }

                path = new PropertyPath(pathString);
            }

            // don't bother to create XmlWorker if we don't even have a valid path
            if (path.SVI.Length > 0)
            {
                // tell Xml Worker if desired result is collection, in order to get optimization
                SetValue(Feature.XmlWorker, new XmlBindingWorker(this, path.SVI[0].drillIn == DrillIn.Never));
            }
            return path;
        }
        private static PropertyPath GetPath(DependencyProperty property)
        {
            PropertyPath path;
            if (PropertyPaths.TryGetValue(property, out path))
            {
                return path;
            }

            path = new PropertyPath(property);
            PropertyPaths[property] = path;
            return path;
        }
示例#16
0
        /// <summary>
        /// Animates property of a given object over time
        /// </summary>
        /// <param name="sender">Object that will be animated</param>
        /// <param name="value">Value of the property</param>
        /// <param name="milliseconds">Timespan of animation</param>
        /// <param name="property">Targeted property</param>
        public static void Fade(DependencyObject sender, double value, double milliseconds, PropertyPath property)
        {
            Storyboard s = new Storyboard();
            DoubleAnimation da = new DoubleAnimation();
            da.To = value;
            da.Duration = new Duration(TimeSpan.FromMilliseconds(milliseconds));

            Storyboard.SetTarget(da, sender);
            Storyboard.SetTargetProperty(da, property);

            s.Children.Add(da);
            s.Begin();
        }
        private PropertyPathWorker(PropertyPath path, DataBindEngine engine)
        {
            _parent = path;
            _arySVS = new SourceValueState[path.Length];
            _engine = engine;

            // initialize each level to NullDataItem, so that the first real
            // item will force a change
            for (int i=_arySVS.Length-1; i>=0; --i)
            {
                _arySVS[i].item = BindingExpression.CreateReference(BindingExpression.NullDataItem);
            }
        }
示例#18
0
 public PropertyChangeNotifier(DependencyObject propertySource, PropertyPath property)
 {
     if (null == propertySource)
         throw new ArgumentNullException("propertySource");
     if (null == property)
         throw new ArgumentNullException("property");
     this._propertySource = new WeakReference(propertySource);
     Binding binding = new Binding();
     binding.Path = property;
     binding.Mode = BindingMode.OneWay;
     binding.Source = propertySource;
     BindingOperations.SetBinding(this, ValueProperty, binding);
 }
        public static DoubleAnimation CreateDoubleAnimation(UIElement uiElement, double from, double to, PropertyPath propertyToAnimate)
        {
            DoubleAnimation animation = new DoubleAnimation();

            Storyboard.SetTarget(animation, uiElement);
            Storyboard.SetTargetProperty(animation, propertyToAnimate);

            // Note that the animation applies to the Canvas.Left property
            animation.From = from ;
            animation.To = to ;
            animation.Duration = TimeSpan.FromMilliseconds(100);

            return animation;
        }
示例#20
0
 internal static BindingExpression Bind(
     DependencyObject target,
     DependencyProperty targetProperty,
     object source,
     PropertyPath path)
 {
     var binding = new Binding
     {
         Path = path,
         Source = source,
         Mode = BindingMode.OneWay,
         UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
     };
     return (BindingExpression)BindingOperations.SetBinding(target, targetProperty, binding);
 }
 public DependencyPropertyListener(
     DependencyObject source,
     PropertyPath property,
     Action<DependencyPropertyChangedEventArgs> onChanged)
 {
     this.Binding = new Binding
     {
         Source = source,
         Path = property,
         Mode = BindingMode.OneWay,
         UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
     };
     this.BindingExpression = (BindingExpression)BindingOperations.SetBinding(this, ProxyProperty, this.Binding);
     this.onChanged = onChanged;
 }
示例#22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MarkupExtension"/> class.
        /// </summary>
        protected MarkupExtension()
        {
            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            Source = this;
            Mode = BindingMode.OneWay;
            Path = new PropertyPath("InternalBindingValue");

#if NETFX_CORE
            Dispatcher.BeginInvoke(UpdateBinding);
#endif
        }
 public static void SmoothSet(this FrameworkElement @this, DependencyProperty dp, double targetvalue, TimeSpan iDuration)
 {
     DoubleAnimation anim = new DoubleAnimation(targetvalue, new Duration(iDuration));
     PropertyPath p = new PropertyPath("(0)", dp);
     Storyboard.SetTargetProperty(anim, p);
     Storyboard sb = new Storyboard();
     sb.Children.Add(anim);
     EventHandler handler = null;
     handler = delegate
     {
         sb.Completed -= handler;
         sb.Remove(@this);
         @this.SetValue(dp, targetvalue);
     };
     sb.Completed += handler;
     sb.Begin(@this, true);
 }
示例#24
0
        public static DoubleAnimationUsingKeyFrames AddAnimation(Storyboard sb, DependencyObject target, PropertyPath property, TimeSpan duration, EquationType type, double from, double to)
        {
            DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames();
            sb.Children.Add(anim);

            Storyboard.SetTarget(anim, target);
            Storyboard.SetTargetProperty(anim, property);

            anim.Duration = new Duration(duration);

            Tween.SetFrom(anim, from);
            Tween.SetTo(anim, to);
            Tween.SetType(anim, type);

            Tween.SetIsInitialize(anim, true);

            return anim;
        }
        internal static void AddRotationAnimation(Storyboard storyboard, TimeSpan animationTime, TimeSpan beginTime, double angleOfRotation, Vector3D axisOfRotation, Quaternion currentRotationQuaternion)
        {
            Quaternion delta = new Quaternion(axisOfRotation, angleOfRotation);
            Quaternion newRotation = currentRotationQuaternion * delta;

            QuaternionAnimation rotationAnimation = new QuaternionAnimation(newRotation, new Duration(animationTime));
            rotationAnimation.AccelerationRatio = 0.5;
            rotationAnimation.DecelerationRatio = 0.5;
            rotationAnimation.BeginTime = beginTime;

            Storyboard.SetTargetName(rotationAnimation, "viewportCamera");

            //Property path for the animation target is going to be the Transform property's Children collection. Specifically the item at index 1 (the first item is the zoom transform),
            //which is our rotation transform, and on it we want to animate the Rotation property's Quarternion property...whew, that was confusing :)
            PropertyPath path = new PropertyPath("(0).(1)[1].(2).(3)", PerspectiveCamera.TransformProperty, Transform3DGroup.ChildrenProperty, RotateTransform3D.RotationProperty, QuaternionRotation3D.QuaternionProperty);
            Storyboard.SetTargetProperty(rotationAnimation, path);

            storyboard.Children.Add(rotationAnimation);
        }
        internal static void AddZoomAnimations(Storyboard storyboard, TimeSpan animationTime, TimeSpan beginTime, double scaleFactor)
        {
            DependencyProperty[] targets = new DependencyProperty[] { ScaleTransform3D.ScaleXProperty, ScaleTransform3D.ScaleYProperty, ScaleTransform3D.ScaleZProperty };

            for (int i = 0; i < targets.Length; i++)
            {
                DoubleAnimation zoomAnimation = new DoubleAnimation(scaleFactor, new Duration(animationTime));
                zoomAnimation.BeginTime = beginTime;

                Storyboard.SetTargetName(zoomAnimation, "viewportCamera");

                //Property path for the animation target is going to be the Transform property's Children collection. Specifically the item at index 0,
                //which is our scaletransform, and on it we want to animate the X, Y and Z properties...whew, that was confusing :)
                PropertyPath path = new PropertyPath("(0).(1)[0].(2)", PerspectiveCamera.TransformProperty, Transform3DGroup.ChildrenProperty, targets[i]);
                Storyboard.SetTargetProperty(zoomAnimation, path);

                storyboard.Children.Add(zoomAnimation);
            }
        }
 public static void BeginElementStoryboard(ResourceDictionary resources, UIElement target, string subTargetName, string StoryboardName, PropertyPath propertyPath, EventHandler completedHandler)
 {
     if (!resources.Contains(StoryboardName))
     {
         throw new ArgumentException(string.Format("Resource with name {0} not found!", StoryboardName));
     }
     if (!string.IsNullOrEmpty(subTargetName))
     {
         target = (target as FrameworkElement).FindName(subTargetName) as UIElement;
     }
     Storyboard sbAlpha = resources[StoryboardName] as Storyboard;
     Storyboard sb = CloneStoryboard(sbAlpha);
     Storyboard.SetTarget(sb, target);
     Storyboard.SetTargetProperty(sb, propertyPath);
     if (completedHandler != null)
     {
         sb.Completed += completedHandler;
     }
     sb.Begin();
 }
示例#28
0
        /// <summary>
        /// Initializes static members of the <see cref="EffectsHelper"/> class.
        /// </summary>
        static EffectsHelper()
        {
#if NETFX_CORE
            var propertyPath = "Opacity";
#else
            var propertyPath = new PropertyPath("Opacity");
#endif

            var dimmAnimation = new DoubleAnimation();
            dimmAnimation.To = DimmedValue;
            dimmAnimation.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200));
            dimmAnimation.SetValue(Storyboard.TargetPropertyProperty, propertyPath);
            _dimmStoryboard.Children.Add(dimmAnimation);

            var undimmAnimation = new DoubleAnimation();
            undimmAnimation.To = UndimmedValue;
            undimmAnimation.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200));
            undimmAnimation.SetValue(Storyboard.TargetPropertyProperty, propertyPath);
            _undimmStoryboard.Children.Add(undimmAnimation);
        }
    public BindingPathValueExtractor(
      string xPath,
      PropertyPath propertyPath,
      bool onlyForWrite,
      Type dataType,
      IValueConverter converter,
      object converterParameter,
      CultureInfo converterCulture )
    {
      m_onlyForWrite = onlyForWrite;
      m_targetType = dataType;
      m_contextDataProvider = new ContextDataProvider();
      m_binding = new Binding();
      m_binding.XPath = xPath;
      m_binding.Path = propertyPath;

      if( converter == null )
        throw new DataGridInternalException( "A Converter must be used" );

      if( onlyForWrite )
      {
        m_binding.Mode = BindingMode.OneWayToSource;
        m_binding.Converter = new ConvertBackInhibitorPassthroughConverter( converter );
        m_binding.ConverterParameter = converterParameter;
        m_binding.ConverterCulture = converterCulture;
      }
      else
      {
        m_binding.Mode = BindingMode.OneWay;
        m_converter = converter;
        m_converterParameter = converterParameter;
        m_converterCulture = converterCulture;
      }

      m_binding.Source = m_contextDataProvider;

      this.SetBinding(
        BindingPathValueExtractor.ValueProperty,
        m_binding );
    }
示例#30
0
        //-----------------------------------------------------
        // 
        //  Constructors 
        //
        //----------------------------------------------------- 

        internal ClrBindingWorker(BindingExpression b, DataBindEngine engine) : base(b)
        {
            PropertyPath path = ParentBinding.Path; 

            if (ParentBinding.XPath != null) 
            { 
                path = PrepareXmlBinding(path);
            } 

            if (path == null)
            {
                path = new PropertyPath(String.Empty); 
            }
 
            if (ParentBinding.Path == null) 
            {
                ParentBinding.UsePath(path); 
            }

            _pathWorker = new PropertyPathWorker(path, this, IsDynamic, engine);
            _pathWorker.SetTreeContext(ParentBindingExpression.TargetElementReference); 
        }
示例#31
0
        private static Storyboard GenerateDynamicTransitionAnimations(FrameworkElement root, VisualStateGroup group, VisualState newState, VisualTransition transition)
        {
            Storyboard dynamic = new Storyboard();

            if (transition != null && transition.GeneratedDuration != null)
            {
                dynamic.Duration = transition.GeneratedDuration;
            }
            else
            {
                dynamic.Duration = new Duration(TimeSpan.Zero);
            }

            Dictionary <TimelineDataToken, Timeline> currentAnimations    = FlattenTimelines(group.CurrentStoryboards);
            Dictionary <TimelineDataToken, Timeline> transitionAnimations = FlattenTimelines(transition != null ? transition.Storyboard : null);
            Dictionary <TimelineDataToken, Timeline> newStateAnimations   = FlattenTimelines(newState.Storyboard);

            // Remove any animations that the transition already animates.
            // There is no need to create an interstitial animation if one already exists.
            foreach (KeyValuePair <TimelineDataToken, Timeline> pair in transitionAnimations)
            {
                currentAnimations.Remove(pair.Key);
                newStateAnimations.Remove(pair.Key);
            }

            // Generate the "to" animations
            foreach (KeyValuePair <TimelineDataToken, Timeline> pair in newStateAnimations)
            {
                // The new "To" Animation -- the root is passed as a reference point for name
                // lookup.
                Timeline toAnimation = GenerateToAnimation(root, pair.Value, true);

                // If the animation is of a type that we can't generate transition animations
                // for, GenerateToAnimation will return null, and we should just keep going.
                if (toAnimation != null)
                {
                    toAnimation.Duration = dynamic.Duration;
                    dynamic.Children.Add(toAnimation);
                }

                // Remove this from the list of current state animations we have to consider next
                currentAnimations.Remove(pair.Key);
            }

            // Generate the "from" animations
            foreach (KeyValuePair <TimelineDataToken, Timeline> pair in currentAnimations)
            {
                Timeline fromAnimation = GenerateFromAnimation(pair.Value);
                if (fromAnimation != null)
                {
                    fromAnimation.Duration = dynamic.Duration;
                    string targetName = Storyboard.GetTargetName(pair.Value);
                    Storyboard.SetTargetName(fromAnimation, targetName);

                    // If the targetName of the existing Animation is known, then look up the
                    // target
                    DependencyObject target = String.IsNullOrEmpty(targetName) ?
                                              null : root.FindName(targetName) as DependencyObject;
                    if (target != null)
                    {
                        Storyboard.SetTarget(fromAnimation, target);
                    }

                    PropertyPath propertyName = Storyboard.GetTargetProperty(pair.Value);
                    Storyboard.SetTargetProperty(fromAnimation, propertyName);
                    dynamic.Children.Add(fromAnimation);
                }
            }

            return(dynamic);
        }
示例#32
0
 public static PropertyPath GetBasePropertyPath(this PropertyPath propertyPath)
 {
     return(propertyPath.Elements.Count() > 1 ? new PropertyPath(propertyPath.Elements.Take(propertyPath.Elements.Count() - 1)) : PropertyPath.Empty);
 }
示例#33
0
 public PropertyPath(string path, params object[] pathParameters)
 {
     this.wpfPropertyPath = new System.Windows.PropertyPath(path, pathParameters);
 }
示例#34
0
 public PropertyPath(object parameter)
 {
     this.wpfPropertyPath = new System.Windows.PropertyPath(parameter);
 }
示例#35
0
 public object ConvertFrom(XamlNamespaces namespaces, Uri sourceUri, object value)
 {
     return(PropertyPath.Parse((string)value, namespaces));
 }
        /// <summary>Converts the specified value object to the <see cref="T:System.Windows.PropertyPath" /> type.</summary>
        /// <param name="typeDescriptorContext">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
        /// <param name="cultureInfo">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture.</param>
        /// <param name="value">The <see cref="T:System.Windows.PropertyPath" /> to convert.</param>
        /// <param name="destinationType">The destination type. This is expected to be the <see cref="T:System.String" /> type.</param>
        /// <returns>The converted destination <see cref="T:System.String" />.</returns>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="value" /> was provided as <see langword="null" />.</exception>
        /// <exception cref="T:System.ArgumentException">The <paramref name="value" /> was not <see langword="null" />, but was not of the expected <see cref="T:System.Windows.PropertyPath" /> type.- or -The <paramref name="destinationType" /> was not the <see cref="T:System.String" /> type.</exception>
        // Token: 0x060007CA RID: 1994 RVA: 0x00018B98 File Offset: 0x00016D98
        public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value, Type destinationType)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            if (null == destinationType)
            {
                throw new ArgumentNullException("destinationType");
            }
            if (destinationType != typeof(string))
            {
                throw new ArgumentException(SR.Get("CannotConvertType", new object[]
                {
                    typeof(PropertyPath),
                    destinationType.FullName
                }));
            }
            PropertyPath propertyPath = value as PropertyPath;

            if (propertyPath == null)
            {
                throw new ArgumentException(SR.Get("UnexpectedParameterType", new object[]
                {
                    value.GetType(),
                    typeof(PropertyPath)
                }), "value");
            }
            if (propertyPath.PathParameters.Count == 0)
            {
                return(propertyPath.Path);
            }
            string path = propertyPath.Path;
            Collection <object> pathParameters = propertyPath.PathParameters;
            XamlDesignerSerializationManager xamlDesignerSerializationManager = (typeDescriptorContext == null) ? null : (typeDescriptorContext.GetService(typeof(XamlDesignerSerializationManager)) as XamlDesignerSerializationManager);
            ValueSerializer         valueSerializer        = null;
            IValueSerializerContext valueSerializerContext = null;

            if (xamlDesignerSerializationManager == null)
            {
                valueSerializerContext = (typeDescriptorContext as IValueSerializerContext);
                if (valueSerializerContext != null)
                {
                    valueSerializer = ValueSerializer.GetSerializerFor(typeof(Type), valueSerializerContext);
                }
            }
            StringBuilder stringBuilder = new StringBuilder();
            int           num           = 0;

            for (int i = 0; i < path.Length; i++)
            {
                if (path[i] == '(')
                {
                    int num2 = i + 1;
                    while (num2 < path.Length && path[num2] != ')')
                    {
                        num2++;
                    }
                    int index;
                    if (int.TryParse(path.Substring(i + 1, num2 - i - 1), NumberStyles.Integer, TypeConverterHelper.InvariantEnglishUS.NumberFormat, out index))
                    {
                        stringBuilder.Append(path.Substring(num, i - num + 1));
                        object                obj = pathParameters[index];
                        DependencyProperty    dependencyProperty;
                        PropertyInfo          propertyInfo;
                        PropertyDescriptor    propertyDescriptor;
                        DynamicObjectAccessor dynamicObjectAccessor;
                        PropertyPath.DowncastAccessor(obj, out dependencyProperty, out propertyInfo, out propertyDescriptor, out dynamicObjectAccessor);
                        Type   type;
                        string text;
                        if (dependencyProperty != null)
                        {
                            type = dependencyProperty.OwnerType;
                            text = dependencyProperty.Name;
                        }
                        else if (propertyInfo != null)
                        {
                            type = propertyInfo.DeclaringType;
                            text = propertyInfo.Name;
                        }
                        else if (propertyDescriptor != null)
                        {
                            type = propertyDescriptor.ComponentType;
                            text = propertyDescriptor.Name;
                        }
                        else if (dynamicObjectAccessor != null)
                        {
                            type = dynamicObjectAccessor.OwnerType;
                            text = dynamicObjectAccessor.PropertyName;
                        }
                        else
                        {
                            type = obj.GetType();
                            text = null;
                        }
                        if (valueSerializer != null)
                        {
                            stringBuilder.Append(valueSerializer.ConvertToString(type, valueSerializerContext));
                        }
                        else
                        {
                            string text2 = null;
                            if (text2 != null && text2 != string.Empty)
                            {
                                stringBuilder.Append(text2);
                                stringBuilder.Append(':');
                            }
                            stringBuilder.Append(type.Name);
                        }
                        if (text != null)
                        {
                            stringBuilder.Append('.');
                            stringBuilder.Append(text);
                            stringBuilder.Append(')');
                        }
                        else
                        {
                            stringBuilder.Append(')');
                            text = (obj as string);
                            if (text == null)
                            {
                                TypeConverter converter = TypeDescriptor.GetConverter(type);
                                if (converter.CanConvertTo(typeof(string)) && converter.CanConvertFrom(typeof(string)))
                                {
                                    try
                                    {
                                        text = converter.ConvertToString(obj);
                                    }
                                    catch (NotSupportedException)
                                    {
                                    }
                                }
                            }
                            stringBuilder.Append(text);
                        }
                        i   = num2;
                        num = num2 + 1;
                    }
                }
            }
            if (num < path.Length)
            {
                stringBuilder.Append(path.Substring(num));
            }
            return(stringBuilder.ToString());
        }
示例#37
0
 public PropertyChangeNotifier(sw.PropertyPath property)
 {
     _property = property ?? throw new ArgumentNullException(nameof(property));
 }
 public override bool CanCreateCommand(System.Windows.PropertyPath path, System.Windows.DependencyObject target)
 {
     return(path != null && target is INotifyAttachedOjectLoaded);
 }
示例#39
0
        public static PropertyPath Insert(this PropertyPath propertyPath, int index, IPropertyPathElement element)
        {
            IEnumerable <IPropertyPathElement> elements = propertyPath.Elements.Take(index).Concat(new [] { element }).Concat(propertyPath.Elements.Skip(index)).ToArray();

            return(new PropertyPath(elements));
        }