/// <summary>
        ///   Adds inspectors for the components of the specified blueprint and its parents.
        /// </summary>
        /// <param name="viewModel">Blueprint to add component inspectors for.</param>
        /// <param name="panel">Panel to add inspectors to.</param>
        /// <param name="getPropertyValue">Callback to get current value for a property.</param>
        /// <param name="onValueChanged">Callback to invoke when a property value changed.</param>
        public void AddComponentInspectorsRecursively(
            BlueprintViewModel viewModel,
            Panel panel,
            GetPropertyValueDelegate getPropertyValue,
            InspectorControlValueChangedDelegate onValueChanged)
        {
            // Add inspectors for parent blueprints.
            if (viewModel.Parent != null)
            {
                this.AddComponentInspectorsRecursively(viewModel.Parent, panel, getPropertyValue, onValueChanged);
            }

            // Add inspectors for specified blueprint.
            foreach (var componentType in viewModel.AddedComponents)
            {
                // Get attributes.
                InspectorType componentInfo = InspectorComponentTable.Instance.GetInspectorType(componentType);
                if (componentInfo == null)
                {
                    continue;
                }

                this.AddInspectorControls(componentInfo, panel, getPropertyValue, onValueChanged);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Adds inspectors for the components of the specified blueprint and its parents.
        /// </summary>
        /// <param name="viewModel">Blueprint to add component inspectors for.</param>
        /// <param name="panel">Panel to add inspectors to.</param>
        /// <param name="getPropertyValue">Callback to get current value for a property.</param>
        /// <param name="onValueChanged">Callback to invoke when a property value changed.</param>
        public void AddComponentInspectorsRecursively(
            BlueprintViewModel viewModel,
            Panel panel,
            GetPropertyValueDelegate getPropertyValue,
            InspectorControlValueChangedDelegate onValueChanged)
        {
            // Add inspectors for parent blueprints.
            if (viewModel.Parent != null)
            {
                this.AddComponentInspectorsRecursively(viewModel.Parent, panel, getPropertyValue, onValueChanged);
            }

            // Add inspectors for specified blueprint.
            foreach (var componentType in viewModel.AddedComponents)
            {
                // Get attributes.
                InspectorType componentInfo = InspectorComponentTable.Instance.GetInspectorType(componentType);
                if (componentInfo == null)
                {
                    continue;
                }

                this.AddInspectorControls(componentInfo, panel, getPropertyValue, onValueChanged);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
 public object GetPropertyValue(dynamic instance, string strPropertyName)
 {
     // InvokeRequired required compares the thread ID of the
     // calling thread to the thread ID of the creating thread.
     // If these threads are different, it returns true.
     if (instance.InvokeRequired)
     {
         GetPropertyValueDelegate gpvd = new GetPropertyValueDelegate(GetPropertyValue);
         return(instance.Invoke(gpvd, new object[] { instance, strPropertyName }));
     }
     else
     {
         Type         type         = instance.GetType();
         PropertyInfo propertyInfo = type.GetProperty(strPropertyName);
         return(propertyInfo.GetValue(instance, new object[] { }));
     }
 }
Exemplo n.º 5
0
        public object GetPropertyValue(object instance, PropertyInfo property)
        {
            GetPropertyValueDelegate dgv = CreateGetPropertyValueDelegate(instance, property);

            return(dgv());
        }
        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);
            }
        }
Exemplo n.º 7
0
 public void InitializeForAutoGeneration(GetPropertyValueDelegate getPropertyValueMethod) => this.GetPropertyValueMethod = getPropertyValueMethod;