private void PrepareLookupWindow() { lookupWindow = new LookupWindow(); lookupWindow.maingrid.FlowDirection = FlowDirection; lookupWindow.title.Text = WindowTitle; lookupWindow.searchpanel.SearchCommand = SearchCommand; lookupWindow.searchpanel.RowMargin = 5; lookupWindow.searchpanel.ColumnMargin = 10; lookupWindow.LookupMode = LookupWindow.LookupModeEnum.Grid; var bind = new Binding("ItemsSource") { Source = this }; BindingOperations.SetBinding(lookupWindow, DataContextProperty, bind); lookupWindow.SelectionMode = SelectionMode; lookupWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen; var sourceType = ItemsSource?.GetType(); if (sourceType != null) { if (sourceType.IsGenericType) { lookupWindow.searchpanel.ModelType = sourceType.GenericTypeArguments[0]; } } if (SearchFields != null) { foreach (var item in SearchFields) { item.Clear(); lookupWindow.searchpanel.SearchFields.Add(item); } } lookupWindow.datagrid.ColumnsToAdd = Columns; if (SelectionMode == LookupSelectionMode.Single) { var buttonColumn = new CustomButtonColumn(); buttonColumn.Image = new BitmapImage(new Uri("/Infra.Wpf;component/Controls/Resources/Select-24.png", UriKind.RelativeOrAbsolute)); buttonColumn.MouseOverImage = new BitmapImage(new Uri("/Infra.Wpf;component/Controls/Resources/SelectOver-24.png", UriKind.RelativeOrAbsolute)); buttonColumn.Width = new C1.WPF.DataGrid.DataGridLength(32); buttonColumn.Order = 0; buttonColumn.Command = SelectCommand; lookupWindow.datagrid.ButtonColumns.Add(buttonColumn); } else { var checkColumn = new CustomCheckBoxColumn(); checkColumn.IsSelectable = true; checkColumn.Binding = new Binding("IsSelected"); checkColumn.Width = new C1.WPF.DataGrid.DataGridLength(32); lookupWindow.datagrid.Columns.Add(checkColumn); } }
private void CustomGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e) { if (!string.IsNullOrEmpty(ColumnsToAdd) || !string.IsNullOrEmpty(ColumnsToRemove)) { string[] removeColumnsList = null; if (!string.IsNullOrEmpty(ColumnsToRemove)) { removeColumnsList = ColumnsToRemove.Split(','); if (removeColumnsList.Contains(e.Property.Name)) { e.Cancel = true; } } if (string.IsNullOrEmpty(ColumnsToRemove)) { string[] addColumnsList = null; if (!string.IsNullOrEmpty(ColumnsToAdd)) { addColumnsList = ColumnsToAdd.Split(','); if (!addColumnsList.Contains(e.Property.Name)) { e.Cancel = true; } } } } string dispalyName = GetDisplayName(e.Property.Name); if (e.Property.PropertyType == typeof(string) || e.Property.PropertyType == typeof(char)) { var customColumn = new CustomTextColumn(); if (e.Property.PropertyType == typeof(char)) { customColumn.MaxLength = 1; } if (!string.IsNullOrEmpty(dispalyName)) { customColumn.Header = dispalyName; } else { customColumn.Header = e.Property.Name; } customColumn.IsReadOnly = true; customColumn.Binding = new Binding(e.Property.Name); e.Column = customColumn; } if (e.Property.PropertyType.IsNumeric()) { var customColumn = new CustomNumericColumn(); if (!string.IsNullOrEmpty(dispalyName)) { customColumn.Header = dispalyName; } else { customColumn.Header = e.Property.Name; } customColumn.IsReadOnly = true; customColumn.Binding = new Binding(e.Property.Name); customColumn.Format = "0,0.##"; if (this.FlowDirection == FlowDirection.RightToLeft) { customColumn.HorizontalAlignment = HorizontalAlignment.Left; } e.Column = customColumn; } if (e.Property.PropertyType == typeof(bool) || e.Property.PropertyType == typeof(bool?)) { var customColumn = new CustomCheckBoxColumn(); if (!string.IsNullOrEmpty(dispalyName)) { customColumn.Header = dispalyName; } else { customColumn.Header = e.Property.Name; } customColumn.IsReadOnly = true; customColumn.Binding = new Binding(e.Property.Name); e.Column = customColumn; } if (e.Property.PropertyType == typeof(ImageSource)) { var customColumn = new DataGridImageColumn(); customColumn.IsReadOnly = true; if (!string.IsNullOrEmpty(dispalyName)) { customColumn.Header = dispalyName; } else { customColumn.Header = e.Property.Name; } customColumn.Binding = new Binding(e.Property.Name); e.Column = customColumn; } if (e.Property.PropertyType == typeof(DateTime) || e.Property.PropertyType == typeof(DateTime?)) { var customColumn = new CustomDateTimeColumn(); if (!string.IsNullOrEmpty(dispalyName)) { customColumn.Header = dispalyName; } else { customColumn.Header = e.Property.Name; } customColumn.IsReadOnly = true; customColumn.Binding = new Binding(e.Property.Name); customColumn.Format = "d"; if (this.FlowDirection == FlowDirection.RightToLeft) { customColumn.HorizontalAlignment = HorizontalAlignment.Left; } e.Column = customColumn; } }