Example #1
0
        public void CreatePropertyBox(GameObjectProperty boundProperty, Panel ParentControl)
        {
            GameObjectProperty property = boundProperty;

            int propertyStripHeight = 20;

            int newPos = (ParentControl.Children.Count) * propertyStripHeight;

            PropertyViewer.Height += 20;
            PropertyViewer.Width   = MainScrollViewer.ActualWidth;

            switch (property.propertyType)
            {
            case PropertyType.BOOL:
                // Create property strip, set text name to property name and make events the property strip can hook to.
                PropertyStripCheckbox propertyStripBool = new PropertyStripCheckbox();

                propertyStripBool.PropertyHeader.Text        = property.RealName;
                propertyStripBool.PropertyCheckBox.IsChecked = property.GetAsBool();
                propertyStripBool.Width = ParentControl.Width;

                ParentControl.Children.Add(propertyStripBool);

                Canvas.SetTop(propertyStripBool, newPos);

                // Event to set property when the checkbox is checked or unchecked.
                propertyStripBool.PropertyCheckBox.Click += (sender, e) =>
                {
                    property.SetValue((bool)propertyStripBool.PropertyCheckBox.IsChecked);
                };

                break;

            case PropertyType.DOUBLE:
                // Create property strip, set text name to property name and make events the property strip can hook to.
                PropertyStripText propertyStripDouble = new PropertyStripText();

                propertyStripDouble.PropertyHeader.Text  = property.RealName;
                propertyStripDouble.PropertyTextBox.Text = property.GetAsDouble().ToString();
                propertyStripDouble.Width = MainScrollViewer.ActualWidth;


                ParentControl.Children.Add(propertyStripDouble);

                Canvas.SetTop(propertyStripDouble, newPos);

                // Event to set property when the textbox is changed if the textbox is a valid double.
                propertyStripDouble.PropertyTextBox.TextChanged += (sender, e) =>
                {
                    double dummyOut;
                    if (double.TryParse(propertyStripDouble.PropertyTextBox.Text, out dummyOut))
                    {
                        propertyStripDouble.PropertyTextBox.Foreground = new SolidColorBrush(Color.FromRgb(189, 195, 199));

                        property.SetValue(dummyOut);
                    }
                    else
                    {
                        propertyStripDouble.PropertyTextBox.Foreground = new SolidColorBrush(Color.FromRgb(181, 74, 47));
                    }
                };
                break;

            case PropertyType.FLOAT:
                // Create property strip, set text name to property name and make events the property strip can hook to.
                PropertyStripText propertyStripFloat = new PropertyStripText();

                propertyStripFloat.PropertyHeader.Text  = property.RealName;
                propertyStripFloat.PropertyTextBox.Text = property.GetAsFloat().ToString();
                propertyStripFloat.Width = MainScrollViewer.ActualWidth;


                ParentControl.Children.Add(propertyStripFloat);

                Canvas.SetTop(propertyStripFloat, newPos);

                // Event to set property when the textbox is changed if the textbox is a valid float.
                propertyStripFloat.PropertyTextBox.TextChanged += (sender, e) =>
                {
                    float dummyOut;
                    if (float.TryParse(propertyStripFloat.PropertyTextBox.Text, out dummyOut))
                    {
                        propertyStripFloat.PropertyTextBox.Foreground = new SolidColorBrush(Color.FromRgb(189, 195, 199));

                        property.SetValue(dummyOut);
                    }
                    else
                    {
                        propertyStripFloat.PropertyTextBox.Foreground = new SolidColorBrush(Color.FromRgb(181, 74, 47));
                    }
                };
                break;

            case PropertyType.INT:
                // Create property strip, set text name to property name and make events the property strip can hook to.
                PropertyStripText propertyStripInt = new PropertyStripText();

                propertyStripInt.PropertyHeader.Text  = property.RealName;
                propertyStripInt.PropertyTextBox.Text = property.GetAsInt32().ToString();
                propertyStripInt.Width = MainScrollViewer.ActualWidth;


                ParentControl.Children.Add(propertyStripInt);

                Canvas.SetTop(propertyStripInt, newPos);

                // Event to set property when the textbox is changed if the textbox is a valid int.
                propertyStripInt.PropertyTextBox.TextChanged += (sender, e) =>
                {
                    int dummyOut;
                    if (int.TryParse(propertyStripInt.PropertyTextBox.Text, out dummyOut))
                    {
                        propertyStripInt.PropertyTextBox.Foreground = new SolidColorBrush(Color.FromRgb(189, 195, 199));

                        property.SetValue(dummyOut);
                    }
                    else
                    {
                        propertyStripInt.PropertyTextBox.Foreground = new SolidColorBrush(Color.FromRgb(181, 74, 47));
                    }
                };
                break;

            case PropertyType.STRING:
                // Create property strip, set text name to property name and make events the property strip can hook to.
                PropertyStripText propertyStripString = new PropertyStripText();

                propertyStripString.PropertyHeader.Text  = property.RealName;
                propertyStripString.PropertyTextBox.Text = property.GetAsString();
                propertyStripString.Width = MainScrollViewer.ActualWidth;


                ParentControl.Children.Add(propertyStripString);

                Canvas.SetTop(propertyStripString, newPos);

                // Event to set property when the textbox is changed if the textbox is a valid int.
                propertyStripString.PropertyTextBox.TextChanged += (sender, e) =>
                {
                    property.SetValue(propertyStripString.PropertyTextBox.Text);
                };

                break;
            }
        }