private NGroupBox CreateSample(string title, NProperty property, double step, double min, double max, int decimalPlaces) { NGroupBox groupBox = new NGroupBox(title); NStackPanel stack = new NStackPanel(); groupBox.Content = stack; stack.VerticalSpacing = 10; NStackPanel propertyStack = new NStackPanel(); stack.Add(new NUniSizeBoxGroup(propertyStack)); propertyStack.HorizontalPlacement = ENHorizontalPlacement.Left; NNumberPropertyEditor editor = CreateEditor(property, step, min, max, decimalPlaces); propertyStack.Add(new NPairBox("Step = ", editor.Step, true)); propertyStack.Add(new NPairBox("Minimum = ", editor.Minimum, true)); propertyStack.Add(new NPairBox("Maximum = ", editor.Maximum, true)); if (editor is NFloatingNumberPropertyEditor) { propertyStack.Add(new NPairBox("Decimal Places = ", ((NFloatingNumberPropertyEditor)editor).DecimalPlaces, true)); } for (int i = 0, count = propertyStack.Count; i < count; i++) { NPairBox pairBox = (NPairBox)propertyStack[i]; NUniSizeBox box1 = (NUniSizeBox)pairBox.Box1; box1.Content.HorizontalPlacement = ENHorizontalPlacement.Right; } stack.Add(editor); return(groupBox); }
private NNumberPropertyEditor CreateEditor(NProperty property, double step, double min, double max, int decimalPlaces) { NNumberPropertyEditor editor = (NNumberPropertyEditor)CreateEditor(property); NSimpleNode node = (NSimpleNode)editor.EditedNode; if (Double.IsNaN(step) == false) { editor.Step = step; } if (Double.IsNaN(min) == false) { editor.Minimum = min; } if (Double.IsNaN(max) == false) { editor.Maximum = max; } if (decimalPlaces != -1 && editor is NFloatingNumberPropertyEditor) { ((NFloatingNumberPropertyEditor)editor).DecimalPlaces = decimalPlaces; } // Ensure the value is in the range [min, max] double value = Convert.ToDouble(node.GetValue(property)); if (value < min) { node.SetValue(property, Convert.ChangeType(editor.Minimum, property.DomType.Type, CultureInfo.InvariantCulture)); } if (value > max) { node.SetValue(property, Convert.ChangeType(editor.Maximum, property.DomType.Type, CultureInfo.InvariantCulture)); } return(editor); }