Esempio n. 1
0
        public void AddInspectorControls(
            InspectorType typeInfo,
            Panel panel,
            GetPropertyValueDelegate getPropertyValue,
            InspectorControlValueChangedDelegate onValueChanged,
            bool addNameLabel = true)
        {
            if (addNameLabel)
            {
                // Add label for component name.
                var componentName = typeInfo.Type.Name;
                componentName = componentName.Replace("Component", string.Empty);
                componentName = componentName.SplitByCapitalLetters();

                Label componentLabel = new Label
                {
                    Content    = componentName,
                    ToolTip    = typeInfo.Description,
                    FontWeight = FontWeights.Bold
                };
                panel.Children.Add(componentLabel);
            }

            // Add inspectors for component properties.
            foreach (var inspectorProperty in typeInfo.Properties)
            {
                // Get current value.
                bool inherited     = true;
                var  propertyValue = getPropertyValue != null
                                        ? getPropertyValue(inspectorProperty, out inherited)
                                        : inspectorProperty.Default;

                // Create control for inspector property.
                IInspectorControl propertyControl = this.CreateInspectorControlFor(
                    inspectorProperty, propertyValue, inherited);
                if (propertyControl == null)
                {
                    continue;
                }

                if (onValueChanged != null)
                {
                    // Subscribe for change of value.
                    propertyControl.ValueChanged += onValueChanged;
                }

                // Create wrapper.
                InspectorWithLabel inspectorWrapper = new InspectorWithLabel
                {
                    DataContext = ((FrameworkElement)propertyControl).DataContext,
                    Control     = propertyControl
                };

                // Add to panel.
                panel.Children.Add(inspectorWrapper);
            }
        }
Esempio n. 2
0
        private void AddItemControl(object item)
        {
            Console.WriteLine("Creating item control");

            IInspectorControl propertyControl =
                this.inspectorFactory.CreateInspectorControlFor(this.itemInspectorProperty, item, false);

            Console.WriteLine("Creating new list inspector item");

            // Create item wrapper.
            ListInspectorItem itemWrapperControl = new ListInspectorItem {
                Control = (InspectorControl)propertyControl
            };

            itemWrapperControl.DeleteClicked += this.OnItemDeleteClicked;
            itemWrapperControl.DownClicked   += this.OnItemDownClicked;
            itemWrapperControl.UpClicked     += this.OnItemUpClicked;
            itemWrapperControl.ValueChanged  += this.OnItemValueChanged;

            Console.WriteLine("Adding new list inspector item");
            this.Items.Children.Add(itemWrapperControl);
            Console.WriteLine("Added new list inspector item");
        }