Exemplo n.º 1
0
 public void SetValue(DependencyProperty dependencyProperty, object value)
 {
     IBinding binding;
     if(_bindings.TryGetValue(dependencyProperty, out binding)) {
         binding.SetValue(value);
     }
 }
Exemplo n.º 2
0
 public object GetValue(DependencyProperty dependencyProperty)
 {
     IBinding binding;
     if(_bindings.TryGetValue(dependencyProperty, out binding)) {
         return binding.GetValue();
     }
     return null;
 }
Exemplo n.º 3
0
        public static DependencyProperty Register(string name, Type propertyType, Type ownerType)
        {
            DependencyProperty dependencyProperty = new DependencyProperty
            {
                Name = name,
                PropertyType = propertyType,
                OwnerType = ownerType
            };

            return dependencyProperty;
        }
Exemplo n.º 4
0
        protected bool SetBinding(DependencyProperty dependencyProperty, object owner, string bindingValue)
        {
            bindingValue = bindingValue.Trim();
            if(!bindingValue.StartsWith("{") && !bindingValue.EndsWith("}")) {
                return false;
            }
            bindingValue = bindingValue.Substring(1, bindingValue.Length - 2).Trim();

            string[] scratch = bindingValue.Split('.');
            if(0 == scratch.Length) {
                return false;
            }

            object source = owner;
            int propertyIndex = 0;

            string propertyName;
            PropertyInfo propertyInfo;
            for(int i=0; i<scratch.Length-1; ++i) {
                propertyName = scratch[i].Trim();

                propertyInfo = source.GetType().GetProperty(propertyName);
                if(null == propertyInfo) {
                    return false;
                }

                source = propertyInfo.GetValue(source, null);
                if(null == source) {
                    return false;
                }

                propertyIndex = i+1;
            }

            propertyName = scratch[propertyIndex].Trim();
            propertyInfo = source.GetType().GetProperty(propertyName);
            if(null == propertyInfo) {
                return false;
            }

            SetBinding(dependencyProperty, new Binding
                {
                    Source = source,
                    SourceProperty = scratch[propertyIndex].Trim()
                }
            );

            return true;
        }
Exemplo n.º 5
0
 public void SetBinding(DependencyProperty dependencyProperty, IBinding binding)
 {
     _bindings[dependencyProperty] = binding;
 }