47 lines
1.6 KiB
C#
47 lines
1.6 KiB
C#
|
using System.Windows;
|
||
|
using System.Windows.Controls;
|
||
|
using System.Windows.Threading;
|
||
|
using System.Linq;
|
||
|
using System.Diagnostics;
|
||
|
|
||
|
namespace CtrEditor.PopUps
|
||
|
{
|
||
|
public partial class MatrixPreviewWindow : Window
|
||
|
{
|
||
|
public MatrixPreviewWindow()
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
}
|
||
|
|
||
|
private void DataGrid_ColumnReordered(object sender, DataGridColumnEventArgs e)
|
||
|
{
|
||
|
if (DataContext is MatrixPreviewViewModel viewModel)
|
||
|
{
|
||
|
// Obtener el nuevo orden basado en DisplayIndex
|
||
|
var orderedColumns = MatrixPreview.Columns
|
||
|
.OrderBy(c => c.DisplayIndex)
|
||
|
.ToList();
|
||
|
|
||
|
// Actualizar los números de columna basado en DisplayIndex
|
||
|
for (int i = 0; i < orderedColumns.Count; i++)
|
||
|
{
|
||
|
var column = orderedColumns[i];
|
||
|
var headerParts = column.Header?.ToString().Split(':');
|
||
|
if (headerParts?.Length == 2)
|
||
|
{
|
||
|
var columnName = headerParts[1];
|
||
|
// Actualizar todos los items que tengan el mismo nombre de columna
|
||
|
var itemsToUpdate = viewModel.MatrixItems.Where(x => x.ColumnName == columnName);
|
||
|
foreach (var item in itemsToUpdate)
|
||
|
{
|
||
|
item.ColumnNumber = i + 1;
|
||
|
}
|
||
|
// Actualizar el header con el nuevo número
|
||
|
column.Header = $"{i + 1}:{columnName}";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|