private void txtPos_KeyPress(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { NumericTextBox axis = (NumericTextBox)sender; if (axis.Value != orgpos) { AxisPositionChanged(GrblInfo.AxisIndexToLetter((int)axis.Tag), axis.Value); } axis.IsReadOnly = true; DROEnabledChanged?.Invoke(false); } }
public Widget(GrblConfigView View, WidgetProperties widget, StackPanel Canvas) { this.Canvas = components = Canvas; this.widget = widget; model = ((WidgetViewModel)Canvas.DataContext); model.NumericValue = double.NaN; Grid grid, labelGrid = null; switch (widget.DataType) { case DataTypes.BOOL: wCheckBox = new CheckBox { Name = "_bool", Content = widget.Label.Trim(), IsEnabled = false }; wCheckBox.Margin = new Thickness(0, 6, 0, 0); grid = labelGrid = AddGrid(200); grid.Children.Add(wCheckBox); Grid.SetColumn(wCheckBox, 1); wCheckBox.Checked += wWidget_TextChanged; components.Children.Add(grid); break; case DataTypes.BITFIELD: case DataTypes.XBITFIELD: has_unit = false; bool axes = widget.Format == "axes"; string[] format = (axes ? "X-Axis,Y-Axis,Z-Axis,A-Axis,B-Axis,C-Axis" : widget.Format).Split(','); for (int i = 0; i < (axes ? 6 : format.Length); i++) { if (axes && !GrblInfo.AxisFlags.HasFlag(GCodeParser.AxisFlag[i])) { continue; } wCheckBox = new CheckBox { Name = string.Format("_bitmask{0}", i), Content = format[i].Trim(), // TabIndex = Canvas.Row, IsEnabled = false, Tag = 1 << i }; grid = AddGrid(300); if (i == 0) { labelGrid = grid; wCheckBox.Margin = new Thickness(0, 6, 0, 0); } else { grid.Height = 20; } grid.Children.Add(wCheckBox); Grid.SetColumn(wCheckBox, 1); wCheckBox.Click += wWidget_TextChanged; components.Children.Add(grid); wCheckBox = null; } break; case DataTypes.RADIOBUTTONS: has_unit = false; string[] rformat = widget.Format.Split(','); for (int i = 0; i < rformat.Length; i++) { wRadiobutton = new RadioButton { Name = string.Format("_radiobutton{0}", i), Content = rformat[i].Trim(), IsEnabled = false, Tag = i }; grid = AddGrid(300); if (i == 0) { labelGrid = grid; wRadiobutton.Margin = new Thickness(0, 6, 0, 0); } else { grid.Height = 20; } grid.Children.Add(wRadiobutton); Grid.SetColumn(wRadiobutton, 1); wRadiobutton.Checked += wWidget_TextChanged; components.Children.Add(grid); wRadiobutton = null; } break; case DataTypes.INTEGER: case DataTypes.FLOAT: wNumericTextBox = new NumericTextBox { Format = widget.Format, Height = 22 }; grid = labelGrid = AddGrid(wNumericTextBox.Width + 4); grid.Children.Add(wNumericTextBox); Grid.SetColumn(wNumericTextBox, 1); components.Children.Add(grid); wNumericTextBox.TextChanged += wWidget_TextChanged; wNumericTextBox.KeyDown += wWidget_KeyDown; Binding binding = new Binding("Text") { Source = Canvas.DataContext, Path = new PropertyPath("NumericValue"), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, ValidatesOnDataErrors = true }; binding.ValidationRules.Add(new NumericRangeRule() { Min = widget.Min, Max = widget.Max }); wNumericTextBox.Style = View.Resources["NumericErrorStyle"] as Style; BindingOperations.SetBinding(wNumericTextBox, NumericTextBox.ValueProperty, binding); model.NumericValue = dbl.Parse(widget.Value); break; default: widget.Format.Replace(" ", ""); wTextBox = new TextBox { Name = "tb_name_xxx", MaxLength = widget.Format.Length //TabIndex = Canvas.Row }; if (widget.DataType == DataTypes.TEXT && widget.Format.StartsWith("x(")) { int length = 8; int.TryParse(widget.Format.Substring(2).Replace(")", ""), out length); wTextBox.MaxLength = length; // this.wTextBox.Size = new System.Drawing.Size(Math.Min(length * PPU, Canvas.Width - x - 15), 20); } else if (widget.DataType == DataTypes.IP4) { wTextBox.MaxLength = 16; Binding sbinding = new Binding("Text") { Source = Canvas.DataContext, Path = new PropertyPath("TextValue"), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, ValidatesOnDataErrors = true }; sbinding.ValidationRules.Add(new IP4ValueRule()); wTextBox.Style = View.Resources["Ip4ErrorStyle"] as Style; BindingOperations.SetBinding(wTextBox, TextBox.TextProperty, sbinding); } grid = labelGrid = AddGrid(); grid.Children.Add(wTextBox); Grid.SetColumn(wTextBox, 1); components.Children.Add(grid); wTextBox.TextChanged += wWidget_TextChanged; wTextBox.KeyDown += wWidget_KeyDown; break; } if (widget.DataType != DataTypes.BOOL && labelGrid != null) { if (widget.Label != "") { wLabel = new Label { Width = 180, Height = 26, HorizontalContentAlignment = HorizontalAlignment.Right, VerticalContentAlignment = VerticalAlignment.Center, Name = "label_xx", Content = widget.Label + ":" }; labelGrid.Children.Add(wLabel); Grid.SetColumn(wLabel, 0); } if (has_unit && widget.Unit != "") { wUnit = new Label { Height = 26, HorizontalContentAlignment = HorizontalAlignment.Left, Name = "unit_xxx", Content = widget.Unit }; labelGrid.Children.Add(wUnit); Grid.SetColumn(wUnit, 2); } } Text = widget.Value; }