private static void NrCellsXYPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { MValueField2DInput instance = d as MValueField2DInput; if (instance == null) { return; } if (instance.NrCellsX < 1 || instance.NrCellsX > MValueField2DBase.MAX_NR_COLS) { return; } if (instance.NrCellsY < 1 || instance.NrCellsY > MValueField2DBase.MAX_NR_ROWS) { return; } // reset grid instance.ResetGrid(); instance.RecalculateTableSizes(instance.NrCellsX, instance.NrCellsY); instance.RedefineTableGrid(); instance.AdaptValueContainers(instance.NrCellsX, instance.NrCellsY); instance.FillInfoCells(); instance.SetUnitLabels(); instance.FillDataCells(); }
private void table_PropertyChanged(object sender, PropertyChangedEventArgs e) { MValueField2DInput table = sender as MValueField2DInput; if (table == null || e == null) { return; } if (e.PropertyName == "AxisValues") { if (!(table.Tag is int)) { return; } int table_index = (int)table.Tag; for (int i = 0; i < this.tables.Count; i++) { if (i == table_index) { continue; } this.tables[i].ApplyAxisValues(table.AxisValues); } } }
private void tabitem_LostFocus(object sender, RoutedEventArgs e) { TabItem ti = sender as TabItem; if (ti == null) { return; } TextBox ti_input = ti.Tag as TextBox; if (ti_input == null) { return; } ti_input.IsEnabled = false; // synchronize table axis values in all tabs MValueField2DInput ti_table = ti.Content as MValueField2DInput; if (ti_table == null) { return; } ti_table.SetAxisValues(); }
private void PopulateTabITem(int _tag, ref TabItem tab_item) { if (tab_item == null) { return; } MValueField2DInput table = new MValueField2DInput(); table.Width = this.Width - 8; table.Height = this.Height - 8; table.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; table.VerticalAlignment = System.Windows.VerticalAlignment.Center; table.NrCellsX = this.NrCellsX; table.NrCellsY = this.NrCellsY; table.UnitX = this.UnitX; table.UnitY = this.UnitY; table.Tag = _tag; table.ShowGridLines = false; table.SnapsToDevicePixels = true; table.PropertyChanged += table_PropertyChanged; tab_item.Content = table; this.tables.Add(table); }
public void FillInfoCellsFromExisting(List <double> _xs, List <double> _ys, List <double> _zs) { if (this.tables == null || this.tables.Count < 1 || _xs == null || _ys == null || _zs == null) { return; } // x, y MValueField2DInput table_0 = this.tables[0]; if (table_0 == null) { return; } List <double> ys = (_ys.Count == 0) ? new List <double> { 0.0 } : _ys; table_0.ApplyAxisValues(new TableAxisValues(_xs, ys)); table_0.SetAxisValues(); // z (number of tables has to be set before this method is called) for (int i = 0; i < this.Items.Count; i++) { if (i > _zs.Count - 1) { continue; } TabItem ti = this.Items[i] as TabItem; if (ti == null) { continue; } TextBox ti_input = ti.Tag as TextBox; if (ti_input == null) { continue; } ti_input.Text = _zs[i].ToString(); } }
private void AdaptTabsToNrCellZChange() { int tab_nr_diff = this.NrCellsZ - this.nr_cell_z_prev; if (tab_nr_diff == 0) { return; } if (tab_nr_diff > 0) { // remove the tab holding the unit z label int nr_items = this.Items.Count; if (nr_items > 1) { this.Items.RemoveAt(nr_items - 1); } // add tabs to existing ones for (int i = 0; i < tab_nr_diff; i++) { // for each 2D Table -> define a separate TAB TabItem ti = new TabItem(); ti.Header = "Tab " + i.ToString(); // input for the table names TextBox ti_input = new TextBox(); ti_input.MinWidth = 25; ti_input.MinHeight = 15; ti_input.Height = 15; ti_input.FontSize = 10; ti_input.Style = (Style)ti_input.TryFindResource("ValueInput"); ti_input.IsEnabled = false; ti.Tag = ti_input; ti.LostFocus += this.tabitem_LostFocus; ti.GotFocus += this.tabitem_GotFocus; // apply style ti.Style = (Style)this.TryFindResource("TabItem_ValueField_Input"); // add a new table this.PopulateTabITem(i, ref ti); // add Tab to the TabControl this.Items.Add(ti); } // add the tab holding the unit z label this.AddUnitZTab("unit Z"); } else { // remove tabs from the back int nr_items = this.Items.Count; for (int i = nr_items - 2; i > this.NrCellsZ - 1; i--) { TabItem ti = this.Items[i] as TabItem; if (ti != null) { MValueField2DInput ti_table = ti.Content as MValueField2DInput; if (ti_table != null) { this.tables.Remove(ti_table); } } this.Items.RemoveAt(i); } } this.nr_cell_z_prev = this.NrCellsZ; }