public static class C1FlexGridExtensions
{
public static ObservableCollection<ColumnConfig> GetBindingColumns(DependencyObject obj)
{
return (ObservableCollection<ColumnConfig>)obj.GetValue(BindingColumnsProperty);
}
public static void SetBindingColumns(DependencyObject obj, ObservableCollection<ColumnConfig> value)
{
obj.SetValue(BindingColumnsProperty, value);
}
// Using a DependencyProperty as the backing store for BindingColumns. This enables animation, styling, binding, etc...
public static readonly DependencyProperty BindingColumnsProperty =
DependencyProperty.RegisterAttached("BindingColumns", typeof(ObservableCollection<ColumnConfig>), typeof(C1FlexGridExtensions), new PropertyMetadata(null, 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,
HeaderBackground = new SolidColorBrush(ColorConverter.ConvertFromString(bindingColumn.ColorString) is Color ? (Color) ColorConverter.ConvertFromString(bindingColumn.ColorString) : Colors.White)
});
}
}
}
}
我是这样绑定的,然后显示
点击列名排序后,再让列名失去焦点
颜色消失了
或者点击左上角,行头和列头交叉的那个方块也会失去颜色 |