private FrameworkElement LoadTable([NotNull] XElement element)
        {
            // data table
            Debug.ArgumentNotNull(element, nameof(element));

            var dataTable = new ResultDataTable
            {
                TableName = @"Table"
            };

            dataTable.RowChanged += DataTableOnRowChanged;

            LoadColumns(dataTable, element);
            LoadRows(dataTable, element);

            dataTable.AcceptChanges();

            DataTables.Add(dataTable);

            // datagrid
            var dataGrid = new DataGrid
            {
                VerticalAlignment     = VerticalAlignment.Stretch,
                RowHeaderWidth        = 0,
                CanUserReorderColumns = false,
                CanUserSortColumns    = false,
                CanUserAddRows        = false,
                CanUserDeleteRows     = false,
                Tag = dataTable
            };

            dataGrid.BeginningEdit += OnBeginningEdit;
            dataGrid.PreviewMouseRightButtonDown += HandleRightMouseDown;

            DataGrids.Add(dataGrid);

            dataGrid.ItemsSource = dataTable.DefaultView;

            return(dataGrid);
        }
        protected virtual List <Control> GetDataRelation(Type model, BindingSource prevBindingSource = null, DataTable prevDataTable = null, string propertyName = null, int?columnId = null)
        {
            var columnsToHide = new List <string>();

            propertyName += "HidenColumn"; //ToDo: To refactor

            var dataGrid   = new DataGridView();
            var bsCustomer = new BindingSource();
            var dataTable  = new DataTable(model.Name);

            DsMain.Tables.Add(dataTable);

            if (prevDataTable != null)
            {
                columnsToHide.Add(propertyName);
                dataTable.Columns.Add(propertyName, typeof(int));
            }
            else
            {
                bsCustomer.DataSource = DsMain;
                bsCustomer.DataMember = model.Name;
                dataGrid.DataSource   = bsCustomer;
                DataGrids.Add(dataGrid);
            }

            var modelProperties = model.GetProperties();

            var counter = 0;

            foreach (var property in modelProperties)
            {
                if (property.PropertyType.IsArray)
                {
                    columnsToHide.Add(property.Name + "HidenColumn");
                    dataTable.Columns.Add(property.Name + "HidenColumn", typeof(int));
                    GetDataRelation(property.PropertyType.GetElementType(), bsCustomer, dataTable, property.Name, counter);
                }
                else
                {
                    if (property.PropertyType.FullName != null &&
                        !(property.PropertyType.IsClass &&
                          !property.PropertyType.FullName.StartsWith("System.")))
                    {
                        dataTable.Columns.Add(property.Name, property.PropertyType);
                    }
                    else
                    {
                        columnsToHide.Add(property.Name + "HidenColumn");
                        dataTable.Columns.Add(property.Name + "HidenColumn", typeof(int));
                        GetDataRelation(property.PropertyType, bsCustomer, dataTable, property.Name, counter);
                    }
                }
                counter++;
            }

            if (prevDataTable != null)
            {
                if (columnId != null)
                {
                    var dataRelation = new DataRelation(model.Name,
                                                        DsMain.Tables[DsMain.Tables.IndexOf(prevDataTable)].Columns[(int)columnId],
                                                        DsMain.Tables[DsMain.Tables.IndexOf(dataTable)].Columns[0], false);

                    DsMain.Relations.Add(dataRelation);
                }
                else
                {
                    throw new NullReferenceException();
                }

                bsCustomer = new BindingSource
                {
                    DataSource = prevBindingSource,
                    DataMember = model.Name
                };

                dataGrid.DataSource = bsCustomer;

                DataGrids.Add(dataGrid);
            }

            HideColumnDictionary.Add(dataGrid, columnsToHide);

            return(DataGrids);
        }