コード例 #1
0
        protected new virtual void Move(int oldIndex, int newIndex)
        {
            MVVMControl control = Items[oldIndex];

            Items.RemoveAt(oldIndex);
            Items.Insert(newIndex, control);
            OnMove(oldIndex, newIndex);
        }
コード例 #2
0
        protected virtual void Insert(int index, object value)
        {
            MVVMControl control = (MVVMControl)Convert(value);

            control._Parent     = this;
            control.DataContext = new MVVMBinding(value);
            control.Build(Root);
            Items.Insert(index, control);
            OnInsert(index, control);
        }
コード例 #3
0
 public MVVMItemsControl(Control control) : base(control)
 {
     OnDefaultDataTemplate = () => new MVVMLabel(new Label()
     {
         AutoSize = true
     })
     {
         Text = new MVVMBinding()
     };
     OnItemsControlInsert = (index, currentControl) => {
         MVVMControl mvvmControl = (MVVMControl)currentControl;
         Control.Controls.Add(mvvmControl.Control);
         Control.Controls.SetChildIndex(mvvmControl.Control, index);
     };
     OnItemsControlRemoveAt = index => Control.Controls.RemoveAt(index);
     OnItemsControlMove     = (oldIndex, newIndex) => Control.Controls.SetChildIndex(Control.Controls[oldIndex], newIndex);
     OnItemsControlReset    = () => Control.Controls.Clear();
 }
コード例 #4
0
 public MVVMBinding(
     MVVMBindingMode mode,
     MVVMUpdateSourceTrigger updateSourceTrigger,
     string path  = null,
     object value = null,
     MVVMRelativeSource relativeSource = null,
     string elementName         = null,
     MVVMControl element        = null,
     bool validatesOnExceptions = false
     )
 {
     if (element != null)
     {
         Type = MVVMBindingType.Element;
     }
     else if (elementName != null)
     {
         Type = MVVMBindingType.ElementName;
     }
     else if (relativeSource != null)
     {
         Type = MVVMBindingType.RelativeSource;
     }
     else if (value != null)
     {
         Type = MVVMBindingType.Value;
     }
     else
     {
         Type = MVVMBindingType.Path;
     }
     _Mode = mode;
     _UpdateSourceTrigger = updateSourceTrigger;
     Path                  = path;
     TargetValue           = value;
     ElementName           = elementName;
     Element               = element;
     ValidatesOnExceptions = validatesOnExceptions;
 }
コード例 #5
0
        internal void Bind(bool isForce = false)
        {
            if (!IsFirstBind && !isForce)
            {
                switch (Type)
                {
                case MVVMBindingType.Value:
                case MVVMBindingType.Element:
                case MVVMBindingType.ElementName:
                case MVVMBindingType.RelativeSource:
                    return;
                }
            }
            IsFirstBind = false;
            Unbind();
            switch (Type)
            {
            case MVVMBindingType.Value:
                break;

            case MVVMBindingType.Path: {
                object dataContext = null;
                if (IsDataContext)
                {
                    if (Control.Parent != null)
                    {
                        dataContext = Control.Parent.DataContext.GetTargetValue();
                    }
                }
                else
                {
                    dataContext = Control.DataContext.GetTargetValue();
                }
                BindSource(dataContext);
                break;
            }

            case MVVMBindingType.Element:
                BindSource(Element);
                break;

            case MVVMBindingType.ElementName: {
                MVVMControl control;
                Control.Root.ControlNames.TryGetValue(ElementName, out control);
                BindSource(control);
                break;
            }

            case MVVMBindingType.RelativeSource: {
                MVVMControl control = Control;
                switch (RelativeSource.Mode)
                {
                case MVVMRelativeSourceMode.Self:
                    break;

                case MVVMRelativeSourceMode.FindAncestor:
                    int ancestorCount = 0;
                    while (control != null)
                    {
                        if (RelativeSource.AncestorType == null || RelativeSource.AncestorType.IsInstanceOfType(control))
                        {
                            ancestorCount++;
                            if (ancestorCount == RelativeSource.AncestorLevel)
                            {
                                break;
                            }
                        }
                        control = control.Parent;
                    }
                    break;

                default:
                    throw new NotImplementedException(RelativeSource.Mode.ToString());
                }
                BindSource(control);
                break;
            }

            default:
                throw new NotImplementedException(Type.ToString());
            }
            OneWaySetTargetValue();
        }
コード例 #6
0
 public MVVMBinding(MVVMControl element, string path, MVVMBindingMode mode, MVVMUpdateSourceTrigger updateSourceTrigger) : this(element, path, mode)
 {
     _UpdateSourceTrigger = updateSourceTrigger;
 }
コード例 #7
0
 public MVVMBinding(MVVMControl element, string path, MVVMBindingMode mode) : this(element, path)
 {
     _Mode = mode;
 }
コード例 #8
0
 public MVVMBinding(MVVMControl element, string path) : this(element) {
     Path = path;
 }
コード例 #9
0
 public MVVMBinding(MVVMControl element, MVVMUpdateSourceTrigger updateSourceTrigger) : this(element) {
     _UpdateSourceTrigger = updateSourceTrigger;
 }
コード例 #10
0
 public MVVMBinding(MVVMControl element, MVVMBindingMode mode) : this(element) {
     _Mode = mode;
 }
コード例 #11
0
 public MVVMBinding(MVVMControl element)
 {
     Element = element;
     Type    = MVVMBindingType.Element;
 }