Example #1
0
        public ComponentEditor(Component component)
        {
            EditorControls = new Dictionary <ComponentProperty, object>();

            ComponentUpdated += new ComponentUpdatedDelegate(ComponentEditor_ComponentUpdated);

            Component = component;

            ComponentProperty[] propertyInfo = component.Description.Properties;

            this.DataContext = component;

            Grid mainGrid = new Grid();

            mainGrid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star)
            });
            mainGrid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star)
            });
            int i = 0;

            foreach (ComponentProperty info in component.Description.Properties)
            {
                mainGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = System.Windows.GridLength.Auto
                });

                if (info.Type == PropertyType.Boolean)
                {
                    CheckBox checkbox = new CheckBox();
                    checkbox.Content   = info.DisplayName;
                    checkbox.IsChecked = (bool)component.GetProperty(info).Value;
                    checkbox.Margin    = new Thickness(5d);
                    checkbox.Tag       = info;

                    checkbox.SetValue(Grid.RowProperty, i);
                    checkbox.SetValue(Grid.ColumnProperty, 0);
                    checkbox.SetValue(Grid.ColumnSpanProperty, 2);

                    checkbox.Checked   += new System.Windows.RoutedEventHandler(BoolChanged);
                    checkbox.Unchecked += new System.Windows.RoutedEventHandler(BoolChanged);

                    mainGrid.Children.Add(checkbox);
                    EditorControls.Add(info, checkbox);
                }
                else if (info.Type == PropertyType.Decimal)
                {
                    Label label = new Label();
                    label.Content = info.DisplayName;
                    label.SetValue(Grid.RowProperty, i);
                    label.SetValue(Grid.ColumnProperty, 0);
                    label.Margin = new Thickness(5d);

                    mainGrid.Children.Add(label);

                    TextBox textbox = new TextBox();
                    textbox.Tag    = info;
                    textbox.Text   = component.GetProperty(info).ToString();
                    textbox.Margin = new Thickness(5d);

                    textbox.SetValue(Grid.RowProperty, i);
                    textbox.SetValue(Grid.ColumnProperty, 1);

                    textbox.TextChanged += new TextChangedEventHandler(DoubleChanged);

                    mainGrid.Children.Add(textbox);
                    EditorControls.Add(info, textbox);
                }
                else if (info.Type == PropertyType.Integer)
                {
                    Label label = new Label();
                    label.Content = info.DisplayName;
                    label.SetValue(Grid.RowProperty, i);
                    label.SetValue(Grid.ColumnProperty, 0);
                    label.Margin = new Thickness(5d);

                    mainGrid.Children.Add(label);

                    TextBox textbox = new TextBox();
                    textbox.Margin = new Thickness(5d);

                    textbox.SetValue(Grid.RowProperty, i);
                    textbox.SetValue(Grid.ColumnProperty, 1);

                    textbox.TextChanged += new TextChangedEventHandler(DoubleChanged);

                    mainGrid.Children.Add(textbox);
                    EditorControls.Add(info, textbox);
                }
                else if (info.Type == PropertyType.Enum)
                {
                    Label label = new Label();
                    label.Content = info.DisplayName;
                    label.SetValue(Grid.RowProperty, i);
                    label.SetValue(Grid.ColumnProperty, 0);
                    label.Margin = new Thickness(5d);

                    mainGrid.Children.Add(label);

                    ComboBox combobox = new ComboBox();
                    combobox.Margin = new Thickness(5d);
                    combobox.Tag    = info;
                    foreach (string option in info.EnumOptions)
                    {
                        combobox.Items.Add(option);
                    }
                    combobox.SelectedItem = component.GetProperty(info);

                    combobox.SetValue(Grid.RowProperty, i);
                    combobox.SetValue(Grid.ColumnProperty, 1);

                    combobox.SelectionChanged += new SelectionChangedEventHandler(EnumChanged);

                    mainGrid.Children.Add(combobox);
                    EditorControls.Add(info, combobox);
                }
                else if (info.Type == PropertyType.String)
                {
                    Label label = new Label();
                    label.Content = info.DisplayName;
                    label.SetValue(Grid.RowProperty, i);
                    label.SetValue(Grid.ColumnProperty, 0);
                    label.Margin = new Thickness(5d);

                    mainGrid.Children.Add(label);

                    TextBox textbox = new TextBox();
                    textbox.Margin       = new Thickness(5d);
                    textbox.Tag          = info;
                    textbox.Text         = component.GetProperty(info).Value as string;
                    textbox.TextChanged += new TextChangedEventHandler(StringChanged);

                    textbox.SetValue(Grid.RowProperty, i);
                    textbox.SetValue(Grid.ColumnProperty, 1);

                    mainGrid.Children.Add(textbox);
                    EditorControls.Add(info, textbox);
                }

                i++;
            }

            this.Content = mainGrid;

            this.Loaded += new RoutedEventHandler(AutomaticEditor_Loaded); // Set previous component data
        }
        public ComponentEditor(Component component)
        {
            EditorControls = new Dictionary<ComponentProperty, object>();

            ComponentUpdated += new ComponentUpdatedDelegate(ComponentEditor_ComponentUpdated);

            Component = component;

            ComponentProperty[] propertyInfo = component.Description.Properties;

            this.DataContext = component;

            Grid mainGrid = new Grid();
            mainGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star) });
            mainGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star) });
            int i = 0;
            foreach (ComponentProperty info in component.Description.Properties)
            {
                mainGrid.RowDefinitions.Add(new RowDefinition() { Height = System.Windows.GridLength.Auto });

                if (info.Type == PropertyType.Boolean)
                {
                    CheckBox checkbox = new CheckBox();
                    checkbox.Content = info.DisplayName;
                    checkbox.IsChecked = (bool)component.GetProperty(info).Value;
                    checkbox.Margin = new Thickness(5d);
                    checkbox.Tag = info;

                    checkbox.SetValue(Grid.RowProperty, i);
                    checkbox.SetValue(Grid.ColumnProperty, 0);
                    checkbox.SetValue(Grid.ColumnSpanProperty, 2);

                    checkbox.Checked += new System.Windows.RoutedEventHandler(BoolChanged);
                    checkbox.Unchecked += new System.Windows.RoutedEventHandler(BoolChanged);

                    mainGrid.Children.Add(checkbox);
                    EditorControls.Add(info, checkbox);
                }
                else if (info.Type == PropertyType.Decimal)
                {
                    Label label = new Label();
                    label.Content = info.DisplayName;
                    label.SetValue(Grid.RowProperty, i);
                    label.SetValue(Grid.ColumnProperty, 0);
                    label.Margin = new Thickness(5d);

                    mainGrid.Children.Add(label);

                    TextBox textbox = new TextBox();
                    textbox.Tag = info;
                    textbox.Text = component.GetProperty(info).ToString();
                    textbox.Margin = new Thickness(5d);

                    textbox.SetValue(Grid.RowProperty, i);
                    textbox.SetValue(Grid.ColumnProperty, 1);

                    textbox.TextChanged += new TextChangedEventHandler(DoubleChanged);

                    mainGrid.Children.Add(textbox);
                    EditorControls.Add(info, textbox);
                }
                else if (info.Type == PropertyType.Integer)
                {
                    Label label = new Label();
                    label.Content = info.DisplayName;
                    label.SetValue(Grid.RowProperty, i);
                    label.SetValue(Grid.ColumnProperty, 0);
                    label.Margin = new Thickness(5d);

                    mainGrid.Children.Add(label);

                    TextBox textbox = new TextBox();
                    textbox.Margin = new Thickness(5d);

                    textbox.SetValue(Grid.RowProperty, i);
                    textbox.SetValue(Grid.ColumnProperty, 1);

                    textbox.TextChanged += new TextChangedEventHandler(DoubleChanged);

                    mainGrid.Children.Add(textbox);
                    EditorControls.Add(info, textbox);
                }
                else if (info.Type == PropertyType.Enum)
                {
                    Label label = new Label();
                    label.Content = info.DisplayName;
                    label.SetValue(Grid.RowProperty, i);
                    label.SetValue(Grid.ColumnProperty, 0);
                    label.Margin = new Thickness(5d);

                    mainGrid.Children.Add(label);

                    ComboBox combobox = new ComboBox();
                    combobox.Margin = new Thickness(5d);
                    combobox.Tag = info;
                    foreach (string option in info.EnumOptions)
                        combobox.Items.Add(option);
                    combobox.SelectedItem = component.GetProperty(info);

                    combobox.SetValue(Grid.RowProperty, i);
                    combobox.SetValue(Grid.ColumnProperty, 1);

                    combobox.SelectionChanged += new SelectionChangedEventHandler(EnumChanged);

                    mainGrid.Children.Add(combobox);
                    EditorControls.Add(info, combobox);
                }
                else if (info.Type == PropertyType.String)
                {
                    Label label = new Label();
                    label.Content = info.DisplayName;
                    label.SetValue(Grid.RowProperty, i);
                    label.SetValue(Grid.ColumnProperty, 0);
                    label.Margin = new Thickness(5d);

                    mainGrid.Children.Add(label);

                    TextBox textbox = new TextBox();
                    textbox.Margin = new Thickness(5d);
                    textbox.Tag = info;
                    textbox.Text = component.GetProperty(info).Value as string;
                    textbox.TextChanged += new TextChangedEventHandler(StringChanged);

                    textbox.SetValue(Grid.RowProperty, i);
                    textbox.SetValue(Grid.ColumnProperty, 1);

                    mainGrid.Children.Add(textbox);
                    EditorControls.Add(info, textbox);
                }

                i++;
            }

            this.Content = mainGrid;

            this.Loaded += new RoutedEventHandler(AutomaticEditor_Loaded); // Set previous component data
        }