コード例 #1
0
        public bool bind(DependencyObject source, object target, Hashtable map, BindingMode mode, params object[] args)
        {
            if (map == null)
            {
                map = ObjectUtils.getMapList(source);
            }
            if ((((((source == null)) || ((target == null)))) || ((map == null))))
            {
                return(false);
            }
            ;

            var relationship = new BindingRelationship();

            relationship.source = source;

            relationship.target = target;

            relationship.map = map;

            relationship.mode = mode;

            relationship.args = args;

            bool result = add(relationship);

            ObjectUtils.copyValues(source, target, map);

            return(result);
        }
コード例 #2
0
        protected bool add(BindingRelationship relationship)
        {
            if (relationship.mode == BindingMode.ONE_TIME)
            {
                return(false);
            }
            ;

            if (contain(relationship))
            {
                return(false);
            }
            ;

            if ((((relationship.mode == BindingMode.ONE_WAY)) || ((relationship.mode == BindingMode.TWO_WAY))))
            {
                //Messenger<DependencyPropertyChangeEvent>.AddListener(DependencyPropertyChangeEvent.CHANGE,onobjectPropertyChange);
                relationship.source.addEventListener(DependencyPropertyChangeEvent.CHANGE, onobjectPropertyChange);
            }
            ;

            if (relationship.mode == BindingMode.TWO_WAY)
            {
                //Messenger<DependencyPropertyChangeEvent>.AddListener(DependencyPropertyChangeEvent.CHANGE,onobjectPropertyChange);
                (relationship.target as DependencyObject).addEventListener(DependencyPropertyChangeEvent.CHANGE,
                                                                           onobjectPropertyChange);
            }
            ;

            list.Add(relationship);

            return(true);
        }
コード例 #3
0
        public void clear()
        {
            var removeList = new ArrayList();

            for (int i = 0; i < list.size; i++)
            {
                BindingRelationship br = list[i];
                if (!removeList.Contains(br.source))
                {
                    removeList.Add(br.source);
                }
                ;

                if (br.mode == BindingMode.TWO_WAY)
                {
                    if (!removeList.Contains(br.target))
                    {
                        removeList.Add(br.target);
                    }
                    ;
                }
                ;
            }
            ;

            foreach (DependencyObject o in removeList)
            {
                o.removeEventListener(DependencyPropertyChangeEvent.CHANGE, onobjectPropertyChange);
                //Messenger<DependencyPropertyChangeEvent>.RemoveListener(DependencyPropertyChangeEvent.CHANGE, this.onobjectPropertyChange);
            }
            ;
            list.Clear();
        }
コード例 #4
0
        protected void onobjectPropertyChange(DependencyPropertyChangeEvent e)
        {
            //	if(e.propertyName=="onlineNum")
            ////MonoBehaviour.print(e.ToString());
            for (int i = 0; i < list.size; i++)
            {
                BindingRelationship br = list[i];

                if (br.mode == BindingMode.ONE_WAY)
                {
                    if (br.source != e.currentTarget)
                    {
                        continue;
                    }
                }
                ;

                if (br.mode == BindingMode.TWO_WAY)
                {
                    if (br.source != e.currentTarget)
                    {
                        continue;
                    }
                }
                ;
                //   if(e.propertyName=="onlineNum")MonoBehaviour.print(br);
                //if (br.source == e.currentTarget){

                //br.target[e.propertyName]=br.source[br.map[e.propertyName]];
                if (br.map.ContainsKey(e.propertyName))
                {
                    if (br.source != null && br.target != null)
                    {
                        ObjectUtils.copyValue(br.source, br.target, e.propertyName, br.map[e.propertyName] as string);
                    }
                    else
                    {
                        Binding.unbind(br.source, br.target);
                    }
                }

                /*} else {
                 *
                 *  if (br.target == e.currentTarget){
                 * //                       br.source[br.map[e.propertyName]]=br.target[e.propertyName];
                 *                              if(br.map.ContainsValue(e.propertyName))
                 *                              ObjectUtils.copyValue( br.target as DependencyObject,br.source,e.propertyName,map[e.propertyName] as string,true);
                 *  };
                 * };*/
            }
            ;
        }
コード例 #5
0
        protected bool contain(BindingRelationship relationship)
        {
            for (int i = 0; i < list.size; i++)
            {
                BindingRelationship br = list[i];
                if (br.source == relationship.source && br.target == relationship.target)
                {
                    return(true);
                }
                ;
            }
            ;

            return(false);
        }
コード例 #6
0
        protected void remove(DependencyObject source, object target)
        {
            bool needRemoveSource = true;

            bool needRemoveTarget = true;

            for (int i = 0; i < list.size; i++)
            {
                BindingRelationship br = list[i];
                if (br.source == source)
                {
                    needRemoveSource = false;
                }
                ;

                if ((((br.target == target)) && ((br.mode == BindingMode.TWO_WAY))))
                {
                    needRemoveTarget = false;
                }
                ;

                if ((((needRemoveSource == false)) && ((needRemoveTarget == false))))
                {
                    break;
                }
            }
            ;

            if (needRemoveSource)
            {
                if (source != null)
                {
                    source.removeEventListener(DependencyPropertyChangeEvent.CHANGE, onobjectPropertyChange);
                }
                //Messenger<DependencyPropertyChangeEvent>.RemoveListener(DependencyPropertyChangeEvent.CHANGE, this.onobjectPropertyChange);
            }
            ;

            if (((needRemoveTarget) && ((target is DependencyObject))))
            {
                (target as DependencyObject).removeEventListener(DependencyPropertyChangeEvent.CHANGE,
                                                                 onobjectPropertyChange);
                //Messenger<DependencyPropertyChangeEvent>.RemoveListener(DependencyPropertyChangeEvent.CHANGE, this.onobjectPropertyChange);
            }
            ;
        }