コード例 #1
0
        public void AddDependentProperty(INPCBinding.PropertyPath prop, PropertyChangedEventHandler handler)
        {
            var dependentProperty = new DependentProperty(prop, handler);

            dependentProperty.Prop.AddHandler(_value, dependentProperty.Handler);

            _dependents.Add(dependentProperty);
        }
コード例 #2
0
        internal void SetValue(object value, INPCBinding.PropertyPath property)
        {
            if (_value == null)
            {
                return;
            }

            property.SetValue(_value, value, null);
        }
コード例 #3
0
        internal object GetValue(INPCBinding.PropertyPath property)
        {
            if (_value == null)
            {
                return(null);
            }

            return(property.GetValue(_value, null));
        }
コード例 #4
0
        internal void SetValue(object value, INPCBinding.PropertyPath property)
        {
            if (_value == null)
            {
                //Debug.LogErrorFormat("Cannot set value for {0}. DataContext on {1} has no value", property, name);
                return;
            }

            property.SetValue(_value, value, null);
        }
コード例 #5
0
        internal object GetValue(INPCBinding.PropertyPath property)
        {
            if (_value == null)
            {
                //Debug.LogErrorFormat("Cannot get value for {0}. DataContext on {1} has no value", property, name);
                return(null);
            }

            return(property.GetValue(_value, null));
        }
コード例 #6
0
        private void FigureBindings()
        {
            Type vmtype;

            if (_viewModel.Component is DataContext)
            {
                vmtype = (_viewModel.Component as DataContext).Type;
            }
            else
            {
                vmtype = _viewModel.Component.GetType();
            }

            _vmProp = new INPCBinding.PropertyPath(_viewModel.Property, vmtype, true);

            if (!_vmProp.IsValid)
            {
                Debug.LogErrorFormat(this, "CommandBinding: Invalid ViewModel property in \"{0}\".",
                                     gameObject.GetParentNameHierarchy());
            }

            if (!typeof(ICommand).IsAssignableFrom(_vmProp.PropertyType))
            {
                _vmProp = null;
            }

            if (_vmProp == null)
            {
                Debug.LogWarningFormat(this, "No property named {0} of type ICommand exists in {1}", _viewModel.Property, vmtype);
            }

            if (_vmProp != null && _vmProp.IsValid)
            {
                if (_viewModel.Component is INotifyPropertyChanged)
                {
                    (_viewModel.Component as INotifyPropertyChanged).PropertyChanged += OnPropertyChanged;
                }

                BindCommand();
            }
        }
コード例 #7
0
ファイル: CommandBinding.cs プロジェクト: jbruening/ugui-mvvm
        private void FigureBindings()
        {
            Type vmtype;
            if (_viewModel.Component is DataContext)
                vmtype = (_viewModel.Component as DataContext).Type;
            else
                vmtype = _viewModel.Component.GetType();

            _vmProp = new INPCBinding.PropertyPath(_viewModel.Property, vmtype, true);
            if (!typeof (ICommand).IsAssignableFrom(_vmProp.PropertyType))
                _vmProp = null;

            if (_vmProp == null)
            {
                Debug.LogWarningFormat("No property named {0} of type ICommand exists in {1}", _viewModel.Property, vmtype);
            }

            if (_vmProp != null && _vmProp.IsValid)
            {
                if (_viewModel.Component is INotifyPropertyChanged)
                    (_viewModel.Component as INotifyPropertyChanged).PropertyChanged += OnPropertyChanged;

                BindCommand();
            }
        }
コード例 #8
0
    /// <summary>
    /// draw an INPCBinding.ComponentPath property
    /// </summary>
    /// <param name="position"></param>
    /// <param name="property"></param>
    /// <param name="label"></param>
    /// <param name="filter"></param>
    public static void DrawCRefProp(SerializedProperty property, GUIContent label, Type filter, bool resolveDataContext = true)
    {
        EditorGUILayout.LabelField(property.displayName);

        SerializedProperty cprop, pprop;
        GetCPathProperties(property, out cprop, out pprop);

        EditorGUI.indentLevel++;
        var position = EditorGUILayout.GetControlRect(true);
        ComponentReferenceDrawer.PropertyField(position, cprop);

        if (cprop.objectReferenceValue != null)
        {
            var name = "propfield" + (GUIUtility.GetControlID(FocusType.Keyboard) + 1);
            GUI.SetNextControlName(name);
            EditorGUILayout.PropertyField(pprop);

            var orv = cprop.objectReferenceValue;
            Type ortype;
            if (orv is DataContext && resolveDataContext)
                ortype = (orv as DataContext).Type;
            else
                ortype = orv.GetType();

            if (ortype == null)
            {
                pprop.stringValue = null;
            }
            else
            {
                var path = new INPCBinding.PropertyPath(pprop.stringValue, ortype);
                Type rtype;
                var idx = Array.FindIndex(path.PPath, p => p == null);
                if (path.IsValid)
                {
                    rtype = path.PPath.Length == 1 ? ortype : path.PPath[path.PPath.Length - 1].PropertyType;
                }
                else
                    rtype = idx - 1 < 0 ? ortype : path.PPath[idx - 1].PropertyType;

                var lrect = GUILayoutUtility.GetLastRect();
                EditorGUI.Toggle(new Rect(lrect.x + EditorGUIUtility.fieldWidth + 5, lrect.y, lrect.width, lrect.height), path.IsValid);

                var props = rtype.GetProperties(BindingFlags.Instance | BindingFlags.Public);

                if (GUI.GetNameOfFocusedControl() == name)
                {
                    var propNames = props.Select(p => p.Name)
                        .OrderByDescending(
                            s => s.IndexOf(path.Parts.LastOrDefault() ?? "", StringComparison.OrdinalIgnoreCase) == 0)
                        .ToArray();

                    var propstring = string.Join("\n",propNames);
                    EditorGUILayout.HelpBox(propstring, MessageType.None);
                }
            }
        }
        else
            pprop.stringValue = null;

        EditorGUI.indentLevel--;
    }
コード例 #9
0
 public DependentProperty(INPCBinding.PropertyPath prop, PropertyChangedEventHandler handler)
 {
     Prop    = prop;
     Handler = handler;
 }
コード例 #10
0
 public void AddDependentProperty(INPCBinding.PropertyPath prop, PropertyChangedEventHandler handler)
 {
     _dependents.Add(new DependentProperty(prop, handler));
 }
コード例 #11
0
    private static void BuildPath(SerializedProperty prop, StringBuilder sw)
    {
        SerializedProperty cprop;
        SerializedProperty pprop;
        INPCBindingEditor.GetCPathProperties(prop, out cprop, out pprop);

        var oval = cprop.objectReferenceValue;
        if (oval == null) return;

        var ppath = new INPCBinding.PropertyPath(pprop.stringValue, oval.GetType());

        if (!ppath.IsValid) return;

        if (_paths.Contains(ppath.PPath))
            return;
        _paths.Add(ppath.PPath);

        sw.AppendFormat(@"  ppa.Register(
        new[]
        {{
        {0}
        }},
        obj =>
        {{
        if(obj == null) return null;
        var v0 = (({1})obj).{2};
        {3}
        }},
        (obj, value) =>
        {{
        {4}
        }});",
            string.Join(",\r\n", ppath.PPath.Select(p =>
                string.Format("        INPCBinding.PropertyPath.GetProperty(typeof({0}), \"{1}\")",
                    GetFullName(p.DeclaringType),
                    p.Name))
                    .ToArray()),
            GetFullName(ppath.PPath[0].DeclaringType),
            ppath.Parts[0],
            BuildGetterEnd(ppath),
            BuildSetterEnd(ppath))
            .AppendLine().AppendLine();
    }