//TODO refactor this class, it's bad style
        public DataGridColumn Generate(Field field, string bindingPath, 
            Action<DbObject, string, DbObject> OnEditDbObjectField, Func<object, string, object, bool> ShowBinaryViewFired)
        {
            DataGridColumn column;

            if(field.DataType == null)
                column = new DataGridTextColumn();
            else if (field.DataType.ToLower().Contains("bool"))
                column = new DataGridCheckBoxColumn();
            else if (field.DataType.ToLower().Contains("system.object"))
                column = new DataGridDbObjectColumn(bindingPath, OnEditDbObjectField);
            else if (field.DataType.ToLower().Contains("system.datetime"))
                column = new DataGridDateTimeColumn();
            else if (field.DataType.ToLower().Contains("system.byte"))
            {
                var binaryColumn = new DataGridBinaryColumn();
                binaryColumn.ShowBinaryViewerFired += ShowBinaryViewFired;
                column = binaryColumn;
            }
            else
                column = new DataGridTextColumn();

            column.Header = field.Name;

            DataGridBoundColumn boundColumn = column as DataGridBoundColumn;

            if (boundColumn != null)
            {
                var binding = new Binding(bindingPath) { Mode = BindingMode.TwoWay };
                boundColumn.Binding = binding;
                if (field.DataType!=null && field.DataType.ToLower().Contains("system.int32"))
                    binding.Converter = new Int32Converter();

            }

            IBindableDataGridColumn bindableDataGridColumn = column as IBindableDataGridColumn;
            if (bindableDataGridColumn != null)
            {
                try
                {
                    bindableDataGridColumn.BindingPath = bindingPath;
                }
                //TODO needed for DataGridDbObjectColumn - remove
                catch (NotImplementedException e)
                {

                }
            }

            return column;
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                stackPanel1.Children.Clear();

                userGrid = new Microsoft.Windows.Controls.DataGrid();

                userGrid.Height = 220;
                //userGrid.MouseDown += new MouseButtonEventHandler(userGrid_MouseClick);
                userGrid.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(userGrid_MouseClick);
                userGrid.SelectionUnit = Microsoft.Windows.Controls.DataGridSelectionUnit.Cell;
                userGrid.SelectionMode = Microsoft.Windows.Controls.DataGridSelectionMode.Extended;

                userGrid.HeadersVisibility   = Microsoft.Windows.Controls.DataGridHeadersVisibility.Column;
                userGrid.GridLinesVisibility = Microsoft.Windows.Controls.DataGridGridLinesVisibility.Horizontal;

                userGrid.IsReadOnly        = true;
                userGrid.Style             = (Style)FindResource("DataGridStyle");
                userGrid.CellStyle         = (Style)FindResource("cellStyle");
                userGrid.RowStyle          = (Style)FindResource("rowStyle");
                userGrid.ColumnHeaderStyle = (Style)FindResource("columnHeaderStyle");
                userGrid.Background        = new SolidColorBrush(Colors.Transparent);

                userGrid.SelectionMode = Microsoft.Windows.Controls.DataGridSelectionMode.Single;
                userGrid.SelectionUnit = Microsoft.Windows.Controls.DataGridSelectionUnit.FullRow;

                Microsoft.Windows.Controls.DataGridCheckBoxColumn col1 = new Microsoft.Windows.Controls.DataGridCheckBoxColumn();
                col1.Width = 48;
                Microsoft.Windows.Controls.DataGridTextColumn col2 = new Microsoft.Windows.Controls.DataGridTextColumn();
                col2.Width = 130;
                Microsoft.Windows.Controls.DataGridTextColumn col3 = new Microsoft.Windows.Controls.DataGridTextColumn();
                //col3.Width = new Microsoft.Windows.Controls.DataGridLength(115, Microsoft.Windows.Controls.DataGridLengthUnitType.Star);
                col3.Width = 115;

                userGrid.Columns.Add(col1);
                userGrid.Columns.Add(col2);
                userGrid.Columns.Add(col3);

                col1.Binding = new Binding("check");
                col2.Binding = new Binding("id");
                col3.Binding = new Binding("nickname");



                for (int j = 0; j < Login.userList.Count; j++)
                {
                    CheckBox chk = new CheckBox();
                    chk.IsChecked = false;
                    userGrid.Items.Add(new ChargeData
                    {
                        check    = chk,
                        id       = Login.userList[j].Id,
                        nickname = Login.userList[j].Nickname
                    });
                }

                col1.Header = "";
                col2.Header = "id";
                col3.Header = "niakName";

                stackPanel1.Children.Add(userGrid);
            }
            catch (Exception ex)
            {
                string strError = ex.ToString();
                ErrorCollection.GetInstance().SetErrorInfo(strError);
            }
        }