public override object GetValueCore(DependencyObject d, DependencyProperty dp)
 {
     if (Root._TemplatedParent == null)
         throw new NotSupportedException("Template content not apply to any element.");
     FrameworkElement element = Root._TemplatedParent;
     if (Property == null)
         return element;
     if (Property.Contains("."))
     {
         string[] dop = Property.Split('.');
         if (dop.Length != 2)
             throw new ArgumentException("Property invalid.");
         Type ownerType = Type.GetType(dop[0]);
         if (ownerType == null)
             return null;
         DependencyProperty property = DependencyProperty.FromName(dop[1], ownerType);
         return element.GetValue(property);
     }
     else
     {
         var propertyInfo = element.GetType().GetProperty(Property);
         if (propertyInfo == null)
             return null;
         DependencyProperty property = DependencyProperty.FromName(Property, propertyInfo.DeclaringType);
         return element.GetValue(property);
     }
 }
 public DependencyPropertyChangedEventArgs(DependencyProperty dp, object oldValue, object newValue)
 {
     if (dp == null)
         throw new NullReferenceException("dp");
     Property = dp;
     NewValue = newValue;
     OldValue = oldValue;
 }
 public void SetValue(DependencyProperty dp, object value)
 {
     if (dp == null)
         throw new ArgumentNullException("dp");
     if (dp.ReadOnly)
         throw new InvalidOperationException("Readonly property not allowed to change.");
     SetValueCore(dp, value);
 }
Exemple #4
0
 protected override object GetValueCore(DependencyProperty dp)
 {
     if (_IsRendering)
     {
         if (_CacheValue.ContainsKey(dp))
             return _CacheValue[dp];
         var value = base.GetValueCore(dp);
         _CacheValue.Add(dp, value);
         return value;
     }
     return base.GetValueCore(dp);
 }
 protected virtual object GetValueCore(DependencyProperty dp)
 {
     if (_LocalValue.ContainsKey(dp))
     {
         object value = _LocalValue[dp];
         Expression expression = value as Expression;
         if (dp.PropertyType != typeof(Expression) && expression != null)
             value = expression.GetValue(this, dp);
         return value;
     }
     return null;
 }
 protected virtual void ClearValueCore(DependencyProperty dp)
 {
     if (_LocalValue.ContainsKey(dp))
     {
         object oldValue = _LocalValue[dp];
         _LocalValue.Remove(dp);
         if (oldValue != dp.DefaultMetadata.DefaultValue && dp.DefaultMetadata.PropertyChangedCallback != null)
         {
             DependencyPropertyChangedEventArgs e = new DependencyPropertyChangedEventArgs(dp, oldValue, dp.DefaultMetadata.DefaultValue);
             dp.DefaultMetadata.PropertyChangedCallback(this, e);
         }
     }
 }
        private static DependencyProperty RegisterCommon(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
        {
            if (string.IsNullOrWhiteSpace(name))
                throw new ArgumentNullException("name");
            if (propertyType == null)
                throw new ArgumentNullException("propertyType");
            if (ownerType == null)
                throw new ArgumentNullException("ownerType");
            FromNameKey key = new FromNameKey(name, ownerType);
            if (_PropertyFromName.Contains(key))
                throw new ArgumentException("The property \"" + name + "\" is exists for \"" + ownerType.FullName + "\"");

            if (typeMetadata == null)
                typeMetadata = new PropertyMetadata();

            DependencyProperty dp = new DependencyProperty();
            dp.Name = name;
            dp.PropertyType = propertyType;
            dp.OwnerType = ownerType;
            dp.DefaultMetadata = typeMetadata;
            dp.ValidateValueCallback = validateValueCallback;

            _PropertyFromName.Add(key, dp);

            return dp;
        }
Exemple #8
0
 public virtual object GetValue(DependencyObject d, DependencyProperty dp)
 {
     return dp.DefaultMetadata.DefaultValue;
 }
 protected internal override BindingExpressionBase GetExpression(DependencyObject d, DependencyProperty dp, IServiceProvider serviceProvider)
 {
     IRootObjectProvider rootProvider = (IRootObjectProvider)serviceProvider.GetService(typeof(IRootObjectProvider));
     FrameworkElement root = rootProvider.RootObject as FrameworkElement;
     return new TemplateBindingExpression(root) { Property = Property };
 }
 protected virtual void OnMerge(PropertyMetadata baseMetadata, DependencyProperty dp)
 {
 }
 protected virtual void OnApply(DependencyProperty dp, Type targetType)
 {
 }
 internal void Merge(PropertyMetadata baseMetadata, DependencyProperty dp)
 {
     CheckFrozen();
     if (_DefaultValue == null)
         _DefaultValue = baseMetadata._DefaultValue;
     if (_PropertyChangedCallback == null)
         _PropertyChangedCallback = baseMetadata._PropertyChangedCallback;
     if (_CoerceValueCallback == null)
         _CoerceValueCallback = baseMetadata._CoerceValueCallback;
     OnMerge(baseMetadata, dp);
 }
 internal void Apply(DependencyProperty dp, Type targetType)
 {
     if (IsFrozen)
         return;
     if (_DefaultValue == null)
     {
         if (targetType.IsValueType)
             _DefaultValue = Activator.CreateInstance(targetType);
     }
     Freeze();
     OnApply(dp, targetType);
 }
 internal DependencyPropertyKey(DependencyProperty dp)
 {
     Property = dp;
 }
 protected virtual void SetValueCore(DependencyProperty dp, object value)
 {
     if (dp.ValidateValueCallback != null)
         if (!dp.ValidateValueCallback(value))
             throw new ArgumentException("Value invalid.");
     if (dp.DefaultMetadata.CoerceValueCallback != null)
         value = dp.DefaultMetadata.CoerceValueCallback(this, value);
     object oldValue;
     if (_LocalValue.ContainsKey(dp))
     {
         oldValue = _LocalValue[dp];
         _LocalValue[dp] = value;
     }
     else
     {
         oldValue = dp.DefaultMetadata.DefaultValue;
         _LocalValue.Add(dp, value);
     }
     if (dp.DefaultMetadata.PropertyChangedCallback != null)
     {
         DependencyPropertyChangedEventArgs e = new DependencyPropertyChangedEventArgs(dp, oldValue, value);
         dp.DefaultMetadata.PropertyChangedCallback(this, e);
     }
 }
 public object GetValue(DependencyProperty dp)
 {
     if (dp == null)
         throw new ArgumentNullException("dp");
     return GetValueCore(dp);
 }