protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) { base.OnPropertyChanged(e); try { IFunctionMemory functionMemory; if (e.Property == ControlMemoryEditor.FunctionMemoryProperty && (functionMemory = this.FunctionMemory) != null) { this.dataGrid.Columns.Clear(); int addressBits = functionMemory.AddressBitWidth; int count = (4 <= addressBits) ? 16 : 1 << addressBits; this.DataDigits = ControlMemoryEditor.HexDigits(functionMemory.DataBitWidth); Style styleViewer = (Style)this.FindResource("cellViewer"); Style styleEditor = (Style)this.FindResource("cellEditor"); for (int i = 0; i < count; i++) { DataGridTextColumn column = new DataGridTextColumn() { Header = string.Format(CultureInfo.InvariantCulture, "{0:X}", i), Binding = new Binding(MemoryEditorRow.ColumnName[i]) { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, ValidatesOnDataErrors = true }, ElementStyle = styleViewer, EditingElementStyle = styleEditor }; this.dataGrid.Columns.Add(column); } this.dataGrid.ItemsSource = this.RowList(); } } catch (Exception exception) { App.Mainframe.ReportException(exception); } }
private List <MemoryEditorRow> RowList() { IFunctionMemory functionMemory = this.FunctionMemory; int cells = Memory.NumberCellsFor(functionMemory.AddressBitWidth); int rows = cells / 16 + (((cells % 16) == 0) ? 0 : 1); string format = "{{0:X{0}}}"; string rowIndexFormat = string.Format(CultureInfo.InvariantCulture, format, Math.Max(1, ControlMemoryEditor.HexDigits(functionMemory.AddressBitWidth) - 1) ); string cellFormat = string.Format(CultureInfo.InvariantCulture, format, ControlMemoryEditor.HexDigits(functionMemory.DataBitWidth)); List <MemoryEditorRow> list = new List <MemoryEditorRow>(rows); for (int i = 0; i < rows; i++) { list.Add(new MemoryEditorRow(functionMemory, i, rowIndexFormat, cellFormat)); } return(list); }