internal static class BindableColumns
{
public static Columns GetColumns(DependencyObject obj)
{
return (Columns)obj.GetValue(ColumnsProperty);
}
public static void SetColumns(DependencyObject obj, Columns value)
{
obj.SetValue(ColumnsProperty, value);
}
// Using a DependencyProperty as the backing store for Columns. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ColumnsProperty =
DependencyProperty.RegisterAttached("Columns", typeof(Columns), typeof(BindableColumns), new PropertyMetadata(null, OnColumnsPropertyChanged));
public static void OnColumnsPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
var dataGrid = obj as SfDataGrid;
if(dataGrid != null)
dataGrid.Columns = args.NewValue as Columns;
}
} |
<ControlTemplate>
<Grid>
<sf:SfDataGrid x:Name="grid"
AllowFiltering="True"
AllowGrouping="True"
ColumnSizer="Star"
AutoGenerateColumns="False"
ItemsSource="{Binding GridItemsSource, RelativeSource={RelativeSource TemplatedParent}}"
local:BindableColumns.Columns="{Binding GridColumns, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
EnableDataVirtualization="True"
NavigationMode="Row"
ShowBusyIndicator="True"
ShowGroupDropArea="True">
</sf:SfDataGrid>
</Grid>
</ControlTemplate> |