Пример #1
0
            object GetValueCore(object o)
            {
                object value;

                if (info == null)
                {
                    value = o;
                }
                else
                {
                    using (info.SetContext(o))
                    {
                        value = info.GetValue();
                    }
                }

                // comparers can deal with null, but not with UnsetValue or null-variants
                if (value == DependencyProperty.UnsetValue ||
                    System.Windows.Data.BindingExpressionBase.IsNullValue(value))
                {
                    value = null;
                }

                return(value);
            }
Пример #2
0
        internal static IObservable <EventPattern <PropertyChangedAndValueEventArgs <TProperty> > > ObservePropertyChangedWithValue <TNotifier, TProperty>(
            this TNotifier source,
            PropertyPath <TNotifier, TProperty> propertyPath,
            bool signalInitial = true) where TNotifier : INotifyPropertyChanged
        {
            var wr         = new WeakReference(source);
            var observable = source.ObservePropertyChanged(propertyPath, false);

            return(Observable.Defer(
                       () =>
            {
                var withValues =
                    observable.Select(
                        x =>
                        new EventPattern <PropertyChangedAndValueEventArgs <TProperty> >(
                            x.Sender,
                            new PropertyChangedAndValueEventArgs <TProperty>(
                                x.EventArgs.PropertyName,
                                propertyPath.GetValue((TNotifier)wr.Target))));
                if (signalInitial)
                {
                    var valueAndSource = propertyPath.GetValueAndSender((TNotifier)wr.Target);
                    var current =
                        new EventPattern <PropertyChangedAndValueEventArgs <TProperty> >(
                            valueAndSource.Source,
                            new PropertyChangedAndValueEventArgs <TProperty>(
                                propertyPath.Last.PropertyInfo.Name,
                                valueAndSource.Value));
                    return Observable.Return(current).Concat(withValues);
                }

                return withValues;
            }));
        }
Пример #3
0
 public static object GetValue(ComponentPath path, PropertyPath prop, bool resolveDataContext = true)
 {
     if (resolveDataContext && path.Component is DataContext)
         return (path.Component as DataContext).GetValue(prop);
     else
         return prop.GetValue(path.Component, null);
 }
Пример #4
0
 public static object GetValue(ComponentPath path, PropertyPath prop, bool resolveDataContext = true)
 {
     if (resolveDataContext && path.Component is DataContext)
     {
         return((path.Component as DataContext).GetValue(prop));
     }
     else
     {
         return(prop.GetValue(path.Component, null));
     }
 }
Пример #5
0
        public void ApplyVToVM()
        {
            //Debug.Log("Applying v to vm");
            if (_vmProp == null || _vProp == null)
            {
                return;
            }

            if (_mode == BindingMode.OneWayToTarget)
            {
                return;
            }

            if (_target.Component == null)
            {
                return;
            }

            if (!enabled)
            {
                return;
            }

            var value = _vProp.GetValue(_target.Component, null);

            if (_ci != null)
            {
                var currentCulture = CultureInfo.CurrentCulture;
                value = _ci.ConvertBack(value, _vmType, null, currentCulture);
            }
            else if (value != null)
            {
                value = System.Convert.ChangeType(value, _vmType);
            }
            else
            {
                value = GetDefaultValue(_vmType);
            }

            if (value is IDelayedValue)
            {
                if (!(value as IDelayedValue).ValueOrSubscribe(SetVmValue, ref value))
                {
                    return;
                }
            }

            SetVmValue(value);
        }
Пример #6
0
        private void TestAddressPath(PropertyPath <Employee, string> path)
        {
            Employee person = new Employee {
                FirstName = "Franz",
                LastName  = "Huber",
                Address   = new Address {
                    City = "NY"
                }
            };

            Assert.AreEqual("NY", path.GetValue(person));

            path.SetValue(person, "LA");
            Assert.AreEqual("LA", person.Address.City);
        }
Пример #7
0
        public TValue GetValue(IBehaviorContext context)
        {
            var sourceObject = _sourceObjectPath.GetValue((TVM)context.VM);

            return(_getter(sourceObject));
        }
 public TValue GetValue(IBehaviorContext vm)
 {
     return(_path.GetValue((TVM)vm.VM));
 }
        public TValue CreateValue(IBehaviorContext context)
        {
            var sourceObject = _sourceObjectPath.GetValue((TVM)context.VM);

            return(_factoryMethod(context, (TVM)context.VM, sourceObject));
        }