コード例 #1
0
        public ValueEditorView(object model, FieldInfo field, ModelValueChangedDelegate modelValueChanged = null) : this()
        {
            this.model = model;
            this.field = field;

            //Classify components : 헤더 등등
            ValueEditorComponentAttribute[] components = field.GetCustomAttributes(typeof(ValueEditorComponentAttribute)).Select(x => (ValueEditorComponentAttribute)x).ToArray();
            foreach (ValueEditorComponentAttribute component in components)
            {
                UserControl view = CreateEditorComponentView(component);

                ValueEditorComponentContext.Children.Add(view);
            }

            //Classify elements : 실제 값
            //ValueName
            ValueEditorAttribute element = field.GetCustomAttribute(typeof(ValueEditorAttribute)) as ValueEditorAttribute;

            ValueNameText = element.valueName;

            //ValueEditor
            UserControl editorElement = CreateEditorElementView(element);

            valueEditorElement = (IValueEditorElement)editorElement;

            valueEditorElement.EditableValueChanged += IEditorElement_ElementValueChanged;
            valueEditorElement.EditableValue         = field.GetValue(model);

            //Outter event
            valueEditorElement.EditableValueChanged += (object value) => {
                modelValueChanged?.Invoke(model, field);
            };

            switch (element.layout)
            {
            case ValueEditorLayout.Wide:
                SetWideEditorElementContext();
                break;
            }

            Children.Add(editorElement);
        }
コード例 #2
0
        public static void CreateValueEditorViews(IEditableModel model, StackPanel editorViewContext, ModelValueChangedDelegate modelValueChanged = null)
        {
            Type modelType = model.GetType();

            FieldInfo[] fields = modelType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (FieldInfo field in fields)
            {
                ValueEditorAttribute editorAttribute = field.GetCustomAttribute(typeof(ValueEditorAttribute)) as ValueEditorAttribute;

                if (editorAttribute == null)
                {
                    continue;
                }

                ValueEditorView valueEditorView = new ValueEditorView(model, field, modelValueChanged);
                editorViewContext.Children.Add(valueEditorView);
            }
        }