//添加一个绑定目标
    public BindHandler AddTarget(BindProperty property, string propertyName = null)
    {
        var bindTarget = new BindTarget()
        {
            target = property,
            action = e =>
            {
                if (propertyName == null || propertyName == e.propertyName)
                {
                    changeAction?.Invoke(e);
                }
            }
        };

        bindTarget.Bind();
        bindTargets.Add(bindTarget);

        return(this);
    }
예제 #2
0
        public void BindNewTestTestSimplePasses()
        {
            var obj0 = new BindProperty <float>(3);
            var obj1 = new BindProperty <float>(4);

            obj0    += obj1;
            obj0.Val = 333;
            Debug.Log(obj0 + " " + obj1);
            Assert.IsTrue(obj0 == obj1);

            obj1.Val = 444;
            Debug.Log(obj0 + " " + obj1);
            Assert.IsFalse(obj0 == obj1);

            obj0 *= obj1;

            obj1.Val = 555;
            Debug.Log(obj0 + " " + obj1);
            Assert.IsTrue(obj0 == obj1);
        }
예제 #3
0
    private void OnModelResponse(Item[] items)
    {
        if (items == null)
        {
            return;
        }

        _view.Title = $"数量:{items.Length}";

        BNodeData[] datas = new BNodeData[items.Length];

        for (int i = 0; i < items.Length; i++)
        {
            int index = i;
            datas[i] = new BNodeData()
            {
                name    = BindProperty <string> .Get(items[i].index.ToString()),
                onClick = BindProperty <Action> .Get(() => OnItem(index))
            };
        }

        _view.Datas = datas;
    }
예제 #4
0
 public ExampleListViewData(int _id, ObservableList <ExampleListViewData> _dataProvider, string _prefabName = "") : base(_id, _prefabName)
 {
     StringName   = new BindProperty <string>(OnNotifyChange);
     DataProvider = _dataProvider;
 }
예제 #5
0
        private void Button_AddCustomBind_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            BindFunctionOpIsAdd = false;
            Binded = true;
            var bindInsType = BindInstance.GetType();

            if (bindInsType.GetInterface(typeof(IEnumerable).FullName, false) != null)
            {
                foreach (var insObj in (IEnumerable)BindInstance)
                {
                    var uiElement = insObj as EngineNS.UISystem.UIElement;
                    //BindFunctionName = $"UIBindFunc_{uiElement.Initializer.Name}_{BindProperty.Name}";
                    BindFunctionName = $"UIBindFunc_{BindProperty.Name}({uiElement.Initializer.Name})";
                    uiElement.PropertyCustomBindAddAction?.Invoke(uiElement, BindProperty.Name, BindProperty.GetPropertyType(uiElement));
                }
            }
            else
            {
                var uiElement = BindInstance as EngineNS.UISystem.UIElement;
                //BindFunctionName = $"UIBindFunc_{uiElement.Initializer.Name}_{BindProperty.Name}";
                BindFunctionName = $"UIBindFunc_{BindProperty.Name}({uiElement.Initializer.Name})";
                uiElement.PropertyCustomBindAddAction?.Invoke(uiElement, BindProperty.Name, BindProperty.GetPropertyType(uiElement));
            }
        }
예제 #6
0
        //bool mBindInitialized = false;
        private void UpdateBindShow()
        {
            //if (mBindInitialized)
            //    return;

            //////ListBox_ClassBind.Items.Clear();
            //////ListBox_ControlBind.Items.Clear();

            //////UISystem.WinBase win = BindInstance as UISystem.WinBase;
            //////if (win != null)
            //////{
            //////    var bindInfos = win.GetPropertyBinds(BindProperty.Name);
            //////    if (bindInfos != null)
            //////    {
            //////        // 新的UI逻辑图,绑定不一样了,这里先注掉
            //////        //////foreach (UISystem.Bind.ClassPropertyBindInfo bindInfo in (from bind in bindInfos where bind is UISystem.Bind.ClassPropertyBindInfo select bind))
            //////        //////{
            //////        //////    ClassPropertyBindControl ctrl = new ClassPropertyBindControl(BindInstance, BindProperty, bindInfo);

            //////        //////    ListBox_ClassBind.Items.Add(ctrl);
            //////        //////}
            //////        //////foreach (UISystem.Bind.ControlPropertyBindInfo bindInfo in (from bind in bindInfos where bind is UISystem.Bind.ControlPropertyBindInfo select bind))
            //////        //////{
            //////        //////    ControlPropertyBindControl ctrl = new ControlPropertyBindControl(BindInstance, BindProperty, bindInfo);

            //////        //////    ListBox_ControlBind.Items.Add(ctrl);
            //////        //////}
            //////        //foreach (var bindInfo in bindInfos)
            //////        //{
            //////        //    if (bindInfo is UISystem.Bind.ClassPropertyBindInfo)
            //////        //    {
            //////        //        ClassPropertyBindControl ctrl = new ClassPropertyBindControl(BindInstance, BindProperty, (UISystem.Bind.ClassPropertyBindInfo)bindInfo);
            //////        //        //ctrl.BindInstance = BindInstance;
            //////        //        //ctrl.BindProperty = BindProperty;
            //////        //        ListBox_ClassBind.Items.Add(ctrl);
            //////        //    }
            //////        //    else if (bindInfo is UISystem.Bind.ControlPropertyBindInfo)
            //////        //    {
            //////        //        ControlPropertyBindControl ctrl = new ControlPropertyBindControl(BindInstance, BindProperty, (UISystem.Bind.ControlPropertyBindInfo)bindInfo);
            //////        //        ListBox_ControlBind.Items.Add(ctrl);
            //////        //    }
            //////        //}
            //////    }
            //////}

            //////if (ListBox_ClassBind.Items.Count > 0 || ListBox_ControlBind.Items.Count > 0)
            //////    Binded = true;
            //////else
            //////    Binded = false;
            IsEnabled = true;
            var bindInsType = BindInstance.GetType();

            if (bindInsType.GetInterface(typeof(IEnumerable).FullName, false) != null)
            {
                // 多选
                int count = 0;
                foreach (var objIns in (IEnumerable)BindInstance)
                {
                    count++;
                }
                if (count > 1)
                {
                    BindFunctionName = "无法同时操作多个控件";
                    IsEnabled        = false;
                }
                foreach (var objIns in (IEnumerable)BindInstance)
                {
                    if (objIns == null)
                    {
                        continue;
                    }

                    var uiElement = objIns as EngineNS.UISystem.UIElement;
                    if (uiElement == null)
                    {
                        continue;
                    }
                    string bindFunctionName;
                    if (uiElement.PropertyBindFunctions.TryGetValue(BindProperty.Name, out bindFunctionName))
                    {
                        BindFunctionName    = $"UIBindFunc_{BindProperty.Name}({uiElement.Initializer.Name})";// bindFunctionName;
                        BindFunctionOpIsAdd = false;
                    }
                    else
                    {
                        BindFunctionOpIsAdd = true;
                    }

                    List <EngineNS.UISystem.VariableBindInfo> varBindInfos;
                    if (uiElement.VariableBindInfosDic.TryGetValue(BindProperty.Name, out varBindInfos))
                    {
                        ListBox_VariableBind.Items.Clear();
                        foreach (var info in varBindInfos)
                        {
                            var ctrl = new EditorCommon.Bind.VariableBind(this, uiElement, info, BindProperty.GetPropertyType(uiElement));
                            ListBox_VariableBind.Items.Add(ctrl);
                        }
                    }

                    UpdateBindShow(uiElement);
                }
            }
            else
            {
                var uiElement = BindInstance as EngineNS.UISystem.UIElement;
                if (uiElement != null)
                {
                    string bindFunctionName;
                    if (uiElement.PropertyBindFunctions.TryGetValue(BindProperty.Name, out bindFunctionName))
                    {
                        BindFunctionName    = $"UIBindFunc_{BindProperty.Name}({uiElement.Initializer.Name})";// bindFunctionName;
                        BindFunctionOpIsAdd = false;
                    }
                    else
                    {
                        BindFunctionOpIsAdd = true;
                    }

                    List <EngineNS.UISystem.VariableBindInfo> varBindInfos;
                    if (uiElement.VariableBindInfosDic.TryGetValue(BindProperty.Name, out varBindInfos))
                    {
                        foreach (var info in varBindInfos)
                        {
                            var ctrl = new EditorCommon.Bind.VariableBind(this, uiElement, info, BindProperty.GetPropertyType(uiElement));
                            ListBox_VariableBind.Items.Add(ctrl);
                        }
                    }

                    UpdateBindShow(uiElement);
                }
            }

            //mBindInitialized = true;
        }