1
+ using System ;
1
2
using System . Windows ;
2
3
using System . Windows . Controls ;
3
4
using System . Windows . Controls . Primitives ;
@@ -7,69 +8,76 @@ namespace MaterialDesignThemes.Wpf
7
8
{
8
9
public static class DataGridAssist
9
10
{
10
- public static readonly DependencyProperty AutoGeneratedCheckBoxBasedOnStyleProperty = DependencyProperty . RegisterAttached (
11
- "AutoGeneratedCheckBoxBasedOnStyle " , typeof ( Style ) , typeof ( DataGridAssist ) , new PropertyMetadata ( default ( Style ) , AutoGeneratedCheckBoxBasedOnStylePropertyChangedCallback ) ) ;
11
+ public static readonly DependencyProperty AutoGeneratedCheckBoxStyleProperty = DependencyProperty . RegisterAttached (
12
+ "AutoGeneratedCheckBoxStyle " , typeof ( Style ) , typeof ( DataGridAssist ) , new PropertyMetadata ( default ( Style ) , AutoGeneratedCheckBoxStylePropertyChangedCallback ) ) ;
12
13
13
- private static void AutoGeneratedCheckBoxBasedOnStylePropertyChangedCallback ( DependencyObject dependencyObject , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
14
+ private static void AutoGeneratedCheckBoxStylePropertyChangedCallback ( DependencyObject dependencyObject , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
14
15
{
15
- //TODO un-sub, consolidate
16
-
17
16
( ( DataGrid ) dependencyObject ) . AutoGeneratingColumn += ( sender , args ) =>
18
17
{
19
18
var dataGridCheckBoxColumn = args . Column as DataGridCheckBoxColumn ;
20
19
if ( dataGridCheckBoxColumn == null ) return ;
21
20
22
- var style = new Style ( typeof ( CheckBox ) , GetAutoGeneratedCheckBoxBasedOnStyle ( dependencyObject ) ) ;
23
- style . Setters . Add ( new Setter ( FrameworkElement . HorizontalAlignmentProperty , HorizontalAlignment . Center ) ) ;
24
- style . Setters . Add ( new Setter ( UIElement . IsHitTestVisibleProperty , false ) ) ;
25
- style . Setters . Add ( new Setter ( UIElement . FocusableProperty , false ) ) ;
26
- dataGridCheckBoxColumn . ElementStyle = style ;
27
- } ;
21
+ dataGridCheckBoxColumn . ElementStyle = GetAutoGeneratedCheckBoxStyle ( dependencyObject ) ;
22
+ } ;
28
23
}
29
24
30
- public static void SetAutoGeneratedCheckBoxBasedOnStyle ( DependencyObject element , Style value )
25
+ public static void SetAutoGeneratedCheckBoxStyle ( DependencyObject element , Style value )
31
26
{
32
- element . SetValue ( AutoGeneratedCheckBoxBasedOnStyleProperty , value ) ;
27
+ element . SetValue ( AutoGeneratedCheckBoxStyleProperty , value ) ;
33
28
}
34
29
35
- public static Style GetAutoGeneratedCheckBoxBasedOnStyle ( DependencyObject element )
30
+ public static Style GetAutoGeneratedCheckBoxStyle ( DependencyObject element )
36
31
{
37
- return ( Style ) element . GetValue ( AutoGeneratedCheckBoxBasedOnStyleProperty ) ;
32
+ return ( Style ) element . GetValue ( AutoGeneratedCheckBoxStyleProperty ) ;
38
33
}
39
34
40
- public static readonly DependencyProperty AutoGeneratedEditingCheckBoxBasedOnStyleProperty = DependencyProperty . RegisterAttached (
41
- "AutoGeneratedEditingCheckBoxBasedOnStyle " , typeof ( Style ) , typeof ( DataGridAssist ) , new PropertyMetadata ( default ( Style ) , AutoGeneratedEditingCheckBoxBasedOnStylePropertyChangedCallback ) ) ;
35
+ public static readonly DependencyProperty AutoGeneratedEditingCheckBoxStyleProperty = DependencyProperty . RegisterAttached (
36
+ "AutoGeneratedEditingCheckBoxStyle " , typeof ( Style ) , typeof ( DataGridAssist ) , new PropertyMetadata ( default ( Style ) , AutoGeneratedEditingCheckBoxStylePropertyChangedCallback ) ) ;
42
37
43
- private static void AutoGeneratedEditingCheckBoxBasedOnStylePropertyChangedCallback ( DependencyObject dependencyObject , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
38
+ private static void AutoGeneratedEditingCheckBoxStylePropertyChangedCallback ( DependencyObject dependencyObject , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
44
39
{
45
- //TODO un-sub, consolidate
46
-
47
40
( ( DataGrid ) dependencyObject ) . AutoGeneratingColumn += ( sender , args ) =>
48
41
{
49
42
var dataGridCheckBoxColumn = args . Column as DataGridCheckBoxColumn ;
50
43
if ( dataGridCheckBoxColumn == null ) return ;
51
44
52
- var style = new Style ( typeof ( CheckBox ) , GetAutoGeneratedCheckBoxBasedOnStyle ( dependencyObject ) ) ;
53
- style . Setters . Add ( new Setter ( FrameworkElement . HorizontalAlignmentProperty , HorizontalAlignment . Center ) ) ;
54
- var binding = new Binding ( ( ( Binding ) dataGridCheckBoxColumn . Binding ) . Path . Path )
55
- {
56
- UpdateSourceTrigger = UpdateSourceTrigger . PropertyChanged ,
57
- Mode = BindingMode . TwoWay
58
- } ;
59
- style . Setters . Add ( new Setter ( ToggleButton . IsCheckedProperty , binding ) ) ;
60
- dataGridCheckBoxColumn . EditingElementStyle = style ;
45
+ dataGridCheckBoxColumn . EditingElementStyle = GetAutoGeneratedEditingCheckBoxStyle ( dependencyObject ) ;
61
46
} ;
62
47
}
63
48
64
- public static void SetAutoGeneratedEditingCheckBoxBasedOnStyle ( DependencyObject element , Style value )
49
+ public static void SetAutoGeneratedEditingCheckBoxStyle ( DependencyObject element , Style value )
50
+ {
51
+ element . SetValue ( AutoGeneratedEditingCheckBoxStyleProperty , value ) ;
52
+ }
53
+
54
+ public static Style GetAutoGeneratedEditingCheckBoxStyle ( DependencyObject element )
55
+ {
56
+ return ( Style ) element . GetValue ( AutoGeneratedEditingCheckBoxStyleProperty ) ;
57
+ }
58
+
59
+ public static readonly DependencyProperty AutoGeneratedEditingTextStyleProperty = DependencyProperty . RegisterAttached (
60
+ "AutoGeneratedEditingTextStyle" , typeof ( Style ) , typeof ( DataGridAssist ) , new PropertyMetadata ( default ( Style ) , AutoGeneratedEditingTextStylePropertyChangedCallback ) ) ;
61
+
62
+ private static void AutoGeneratedEditingTextStylePropertyChangedCallback ( DependencyObject dependencyObject , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
65
63
{
66
- element . SetValue ( AutoGeneratedEditingCheckBoxBasedOnStyleProperty , value ) ;
64
+ ( ( DataGrid ) dependencyObject ) . AutoGeneratingColumn += ( sender , args ) =>
65
+ {
66
+ var dataGridTextColumn = args . Column as DataGridTextColumn ;
67
+ if ( dataGridTextColumn == null ) return ;
68
+
69
+ dataGridTextColumn . EditingElementStyle = GetAutoGeneratedEditingTextStyle ( dependencyObject ) ;
70
+ } ;
67
71
}
68
72
69
- public static Style GetAutoGeneratedEditingCheckBoxBasedOnStyle ( DependencyObject element )
73
+ public static void SetAutoGeneratedEditingTextStyle ( DependencyObject element , Style value )
70
74
{
71
- return ( Style ) element . GetValue ( AutoGeneratedEditingCheckBoxBasedOnStyleProperty ) ;
75
+ element . SetValue ( AutoGeneratedEditingTextStyleProperty , value ) ;
72
76
}
73
77
78
+ public static Style GetAutoGeneratedEditingTextStyle ( DependencyObject element )
79
+ {
80
+ return ( Style ) element . GetValue ( AutoGeneratedEditingTextStyleProperty ) ;
81
+ }
74
82
}
75
83
}
0 commit comments