@@ -16,6 +16,10 @@ namespace Wpf.Ui.Controls;
16
16
/// </summary>
17
17
[ StyleTypedProperty ( Property = nameof ( CheckBoxColumnElementStyle ) , StyleTargetType = typeof ( CheckBox ) ) ]
18
18
[ StyleTypedProperty ( Property = nameof ( CheckBoxColumnEditingElementStyle ) , StyleTargetType = typeof ( CheckBox ) ) ]
19
+ [ StyleTypedProperty ( Property = nameof ( ComboBoxColumnElementStyle ) , StyleTargetType = typeof ( ComboBox ) ) ]
20
+ [ StyleTypedProperty ( Property = nameof ( ComboBoxColumnEditingElementStyle ) , StyleTargetType = typeof ( ComboBox ) ) ]
21
+ [ StyleTypedProperty ( Property = nameof ( TextColumnElementStyle ) , StyleTargetType = typeof ( TextBlock ) ) ]
22
+ [ StyleTypedProperty ( Property = nameof ( TextColumnEditingElementStyle ) , StyleTargetType = typeof ( TextBox ) ) ]
19
23
public class DataGrid : System . Windows . Controls . DataGrid
20
24
{
21
25
/// <summary>Identifies the <see cref="CheckBoxColumnElementStyle"/> dependency property.</summary>
@@ -36,6 +40,42 @@ public class DataGrid : System.Windows.Controls.DataGrid
36
40
new FrameworkPropertyMetadata ( null )
37
41
) ;
38
42
43
+ /// <summary>Identifies the <see cref="ComboBoxColumnElementStyle"/> dependency property.</summary>
44
+ public static readonly DependencyProperty ComboBoxColumnElementStyleProperty =
45
+ DependencyProperty . Register (
46
+ nameof ( ComboBoxColumnElementStyle ) ,
47
+ typeof ( Style ) ,
48
+ typeof ( DataGrid ) ,
49
+ new FrameworkPropertyMetadata ( null )
50
+ ) ;
51
+
52
+ /// <summary>Identifies the <see cref="ComboBoxColumnEditingElementStyle"/> dependency property.</summary>
53
+ public static readonly DependencyProperty ComboBoxColumnEditingElementStyleProperty =
54
+ DependencyProperty . Register (
55
+ nameof ( ComboBoxColumnEditingElementStyle ) ,
56
+ typeof ( Style ) ,
57
+ typeof ( DataGrid ) ,
58
+ new FrameworkPropertyMetadata ( null )
59
+ ) ;
60
+
61
+ /// <summary>Identifies the <see cref="TextColumnElementStyle"/> dependency property.</summary>
62
+ public static readonly DependencyProperty TextColumnElementStyleProperty =
63
+ DependencyProperty . Register (
64
+ nameof ( TextColumnElementStyle ) ,
65
+ typeof ( Style ) ,
66
+ typeof ( DataGrid ) ,
67
+ new FrameworkPropertyMetadata ( null )
68
+ ) ;
69
+
70
+ /// <summary>Identifies the <see cref="TextColumnEditingElementStyle"/> dependency property.</summary>
71
+ public static readonly DependencyProperty TextColumnEditingElementStyleProperty =
72
+ DependencyProperty . Register (
73
+ nameof ( TextColumnEditingElementStyle ) ,
74
+ typeof ( Style ) ,
75
+ typeof ( DataGrid ) ,
76
+ new FrameworkPropertyMetadata ( null )
77
+ ) ;
78
+
39
79
/// <summary>
40
80
/// Gets or sets the style which is applied to all checkbox column in the DataGrid
41
81
/// </summary>
@@ -54,6 +94,42 @@ public Style? CheckBoxColumnEditingElementStyle
54
94
set => SetValue ( CheckBoxColumnEditingElementStyleProperty , value ) ;
55
95
}
56
96
97
+ /// <summary>
98
+ /// Gets or sets the style which is applied to all combobox column in the DataGrid
99
+ /// </summary>
100
+ public Style ? ComboBoxColumnElementStyle
101
+ {
102
+ get => ( Style ? ) GetValue ( ComboBoxColumnElementStyleProperty ) ;
103
+ set => SetValue ( ComboBoxColumnElementStyleProperty , value ) ;
104
+ }
105
+
106
+ /// <summary>
107
+ /// Gets or sets the style for all the column comboboxes in the DataGrid
108
+ /// </summary>
109
+ public Style ? ComboBoxColumnEditingElementStyle
110
+ {
111
+ get => ( Style ? ) GetValue ( ComboBoxColumnEditingElementStyleProperty ) ;
112
+ set => SetValue ( ComboBoxColumnEditingElementStyleProperty , value ) ;
113
+ }
114
+
115
+ /// <summary>
116
+ /// Gets or sets the style which is applied to all textbox column in the DataGrid
117
+ /// </summary>
118
+ public Style ? TextColumnElementStyle
119
+ {
120
+ get => ( Style ? ) GetValue ( TextColumnElementStyleProperty ) ;
121
+ set => SetValue ( TextColumnElementStyleProperty , value ) ;
122
+ }
123
+
124
+ /// <summary>
125
+ /// Gets or sets the style for all the column textboxes in the DataGrid
126
+ /// </summary>
127
+ public Style ? TextColumnEditingElementStyle
128
+ {
129
+ get => ( Style ? ) GetValue ( TextColumnEditingElementStyleProperty ) ;
130
+ set => SetValue ( TextColumnEditingElementStyleProperty , value ) ;
131
+ }
132
+
57
133
protected override void OnInitialized ( EventArgs e )
58
134
{
59
135
Columns . CollectionChanged += ColumnsOnCollectionChanged ;
@@ -78,35 +154,109 @@ private void UpdateColumnElementStyles()
78
154
79
155
private void UpdateSingleColumn ( DataGridColumn dataGridColumn )
80
156
{
81
- if ( dataGridColumn is DataGridCheckBoxColumn checkBoxColumn )
157
+ switch ( dataGridColumn )
82
158
{
83
- if (
84
- checkBoxColumn . ReadLocalValue ( DataGridCheckBoxColumn . ElementStyleProperty )
85
- == DependencyProperty . UnsetValue
86
- )
87
- {
88
- _ = BindingOperations . SetBinding (
89
- checkBoxColumn ,
90
- DataGridCheckBoxColumn . ElementStyleProperty ,
91
- new Binding { Path = new PropertyPath ( CheckBoxColumnElementStyleProperty ) , Source = this }
92
- ) ;
93
- }
94
-
95
- if (
96
- checkBoxColumn . ReadLocalValue ( DataGridCheckBoxColumn . EditingElementStyleProperty )
97
- == DependencyProperty . UnsetValue
98
- )
99
- {
100
- _ = BindingOperations . SetBinding (
101
- checkBoxColumn ,
102
- DataGridCheckBoxColumn . EditingElementStyleProperty ,
103
- new Binding
104
- {
105
- Path = new PropertyPath ( CheckBoxColumnEditingElementStyleProperty ) ,
106
- Source = this ,
107
- }
108
- ) ;
109
- }
159
+ case DataGridCheckBoxColumn checkBoxColumn :
160
+ if (
161
+ checkBoxColumn . ReadLocalValue ( DataGridBoundColumn . ElementStyleProperty )
162
+ == DependencyProperty . UnsetValue
163
+ )
164
+ {
165
+ _ = BindingOperations . SetBinding (
166
+ checkBoxColumn ,
167
+ DataGridBoundColumn . ElementStyleProperty ,
168
+ new Binding { Path = new PropertyPath ( CheckBoxColumnElementStyleProperty ) , Source = this }
169
+ ) ;
170
+ }
171
+
172
+ if (
173
+ checkBoxColumn . ReadLocalValue ( DataGridBoundColumn . EditingElementStyleProperty )
174
+ == DependencyProperty . UnsetValue
175
+ )
176
+ {
177
+ _ = BindingOperations . SetBinding (
178
+ checkBoxColumn ,
179
+ DataGridBoundColumn . EditingElementStyleProperty ,
180
+ new Binding
181
+ {
182
+ Path = new PropertyPath ( CheckBoxColumnEditingElementStyleProperty ) , Source = this
183
+ }
184
+ ) ;
185
+ }
186
+
187
+ break ;
188
+
189
+ case DataGridComboBoxColumn comboBoxColumn :
190
+ if (
191
+ comboBoxColumn . ReadLocalValue ( DataGridBoundColumn . ElementStyleProperty )
192
+ == DependencyProperty . UnsetValue
193
+ )
194
+ {
195
+ _ = BindingOperations . SetBinding (
196
+ comboBoxColumn ,
197
+ DataGridBoundColumn . ElementStyleProperty ,
198
+ new Binding { Path = new PropertyPath ( ComboBoxColumnElementStyleProperty ) , Source = this }
199
+ ) ;
200
+ }
201
+
202
+ if (
203
+ comboBoxColumn . ReadLocalValue ( DataGridBoundColumn . EditingElementStyleProperty )
204
+ == DependencyProperty . UnsetValue
205
+ )
206
+ {
207
+ _ = BindingOperations . SetBinding (
208
+ comboBoxColumn ,
209
+ DataGridBoundColumn . EditingElementStyleProperty ,
210
+ new Binding
211
+ {
212
+ Path = new PropertyPath ( ComboBoxColumnEditingElementStyleProperty ) , Source = this
213
+ }
214
+ ) ;
215
+ }
216
+
217
+ if (
218
+ comboBoxColumn . ReadLocalValue ( DataGridBoundColumn . EditingElementStyleProperty )
219
+ == DependencyProperty . UnsetValue
220
+ )
221
+ {
222
+ _ = BindingOperations . SetBinding (
223
+ comboBoxColumn ,
224
+ DataGridBoundColumn . EditingElementStyleProperty ,
225
+ new Binding
226
+ {
227
+ Path = new PropertyPath ( ComboBoxColumnEditingElementStyleProperty ) , Source = this
228
+ }
229
+ ) ;
230
+ }
231
+
232
+ break ;
233
+
234
+ case DataGridTextColumn textBoxColumn :
235
+ if (
236
+ textBoxColumn . ReadLocalValue ( DataGridBoundColumn . ElementStyleProperty )
237
+ == DependencyProperty . UnsetValue
238
+ )
239
+ {
240
+ _ = BindingOperations . SetBinding (
241
+ textBoxColumn ,
242
+ DataGridBoundColumn . ElementStyleProperty ,
243
+ new Binding { Path = new PropertyPath ( TextColumnElementStyleProperty ) , Source = this }
244
+ ) ;
245
+ }
246
+
247
+ if (
248
+ textBoxColumn . ReadLocalValue ( DataGridBoundColumn . EditingElementStyleProperty )
249
+ == DependencyProperty . UnsetValue
250
+ )
251
+ {
252
+ _ = BindingOperations . SetBinding (
253
+ textBoxColumn ,
254
+ DataGridBoundColumn . EditingElementStyleProperty ,
255
+ new Binding { Path = new PropertyPath ( TextColumnEditingElementStyleProperty ) , Source = this }
256
+ ) ;
257
+ }
258
+
259
+ break ;
110
260
}
111
261
}
112
262
}
0 commit comments