如图,Filter 是在Xaml 里的,列绑定是写的附加依赖属性绑定的
- public static readonly DependencyProperty BindingColumnsProperty =
- DependencyProperty.RegisterAttached("BindingColumns", typeof(ObservableCollection<ColumnConfig>),
- typeof(FlexGridExtensions), new PropertyMetadata(null, BindingColumnsChanged));
复制代码
在BindingColumnsChanged事件里
- private static void BindingColumnsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- var bindingColumns = e.NewValue as ObservableCollection<ColumnConfig>;
- if(bindingColumns != null)
- {
- var c1FlexGrid = d as C1FlexGrid;
- if(c1FlexGrid != null)
- {
- foreach(var bindingColumn in bindingColumns)
- {
- c1FlexGrid.Columns.Add(new Column
- {
- Header = bindingColumn.HeaderName,
- Binding = new Binding(bindingColumn.ColumnName),
- Width = new GridLength(bindingColumn.Width),
- Format = bindingColumn.FormatString,
- ToolTip = bindingColumn.HeaderDescription,
- HeaderBackground = new SolidColorBrush(ColorConverter.ConvertFromString(bindingColumn.HeaderColorString) is Color ? (Color)ColorConverter.ConvertFromString(bindingColumn.HeaderColorString) : Colors.White),
- });
- }
-
- c1FlexGrid.CellFactory = new FlexGridCellFactory();
- }
- }
- }
复制代码
使用系统WIN10 10041中文简体版,VS2013 update4 中文简体版 |