using System;
using System.Collections.Generic;
using System.Windows.Controls;

namespace QC.QTMApplication;

[Serializable]
public class WPFDataGridSettings
{
	private List<WPFDataGridColumnSettings> columnSettings = new List<WPFDataGridColumnSettings>();

	public List<WPFDataGridColumnSettings> ColumnSettings
	{
		get
		{
			return columnSettings;
		}
		set
		{
			columnSettings = value;
		}
	}

	public void LoadGridSettings(DataGrid dataGrid)
	{
		if (dataGrid != null)
		{
			DataGridLengthConverter dataGridLengthConverter = new DataGridLengthConverter();
			for (int i = 0; i < dataGrid.Columns.Count; i++)
			{
				dataGrid.Columns[i].Width = (DataGridLength)dataGridLengthConverter.ConvertFromString(columnSettings[i].ColumnWidth);
			}
		}
	}

	public void SaveGridSettings(DataGrid dataGrid)
	{
		if (dataGrid != null)
		{
			columnSettings.Clear();
			DataGridLengthConverter dataGridLengthConverter = new DataGridLengthConverter();
			for (int i = 0; i < dataGrid.Columns.Count; i++)
			{
				WPFDataGridColumnSettings wPFDataGridColumnSettings = new WPFDataGridColumnSettings();
				wPFDataGridColumnSettings.ColumnWidth = dataGridLengthConverter.ConvertToString(dataGrid.Columns[i].Width);
				columnSettings.Add(wPFDataGridColumnSettings);
			}
		}
	}
}
