1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
public class DataGridCheckBoxAllColumn : DataGridCheckBoxColumn
{
public Binding BindingAll
{
get;
set;
}
public override Binding Binding
{
get
{
return base.Binding;
}
set
{
base.Binding = value;
}
}
bool isLoaded = false;
// on se sert de cette methode comme d'une methode Load :)
protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
{
if (isLoaded == false)
{
isLoaded = true;
string xaml = @"<ControlTemplate
xmlns=""http://schemas.microsoft.com/client/2007"">
<CheckBox ";
if( this.BindingAll != null )
{
xaml += @"IsChecked=""{Binding " + this.BindingAll.Path.Path + @",Mode=TwoWay}""";
}
xaml += @"/>";
xaml += @"</ControlTemplate>";
ControlTemplate template = (ControlTemplate)XamlReader.Load(
xaml
);
Style style = new Style(typeof(DataGridColumnHeader));
style.Setters.Add(new Setter(DataGridColumnHeader.TemplateProperty, template));
this.HeaderStyle = style;
}
return base.GenerateElement(cell, dataItem);
}
} |
Partager