@@ -204,6 +204,15 @@ public bool CanFilter
204
204
set => SetValue ( CanFilterProperty , value ) ;
205
205
}
206
206
207
+ /// <summary>
208
+ /// Gets or sets the order in which this column should be displayed.
209
+ /// </summary>
210
+ public int ? Order
211
+ {
212
+ get => ( int ? ) GetValue ( OrderProperty ) ;
213
+ set => SetValue ( OrderProperty , value ) ;
214
+ }
215
+
207
216
internal TableViewColumnsCollection ? OwningCollection { get ; set ; }
208
217
209
218
/// <summary>
@@ -293,69 +302,32 @@ internal void EnsureHeaderStyle()
293
302
/// <summary>
294
303
/// Handles changes to the Width property.
295
304
/// </summary>
296
- private static void OnWidthChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
297
- {
298
- if ( d is TableViewColumn column && column . OwningCollection is { } )
299
- {
300
- column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( Width ) ) ;
301
- }
302
- }
303
-
304
- /// <summary>
305
- /// Handles changes to the MinWidth property.
306
- /// </summary>
307
- private static void OnMinWidthChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
308
- {
309
- if ( d is TableViewColumn column && column . OwningCollection is { } )
310
- {
311
- column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( MinWidth ) ) ;
312
- }
313
- }
314
-
315
- /// <summary>
316
- /// Handles changes to the MaxWidth property.
317
- /// </summary>
318
- private static void OnMaxWidthChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
319
- {
320
- if ( d is TableViewColumn column && column . OwningCollection is { } )
321
- {
322
- column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( MaxWidth ) ) ;
323
- }
324
- }
325
-
326
- /// <summary>
327
- /// Handles changes to the ActualWidth property.
328
- /// </summary>
329
- private static void OnActualWidthChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
330
- {
331
- if ( d is TableViewColumn column && column . OwningCollection is { } )
332
- {
333
- column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( ActualWidth ) ) ;
334
- }
335
- }
336
-
337
- /// <summary>
338
- /// Handles changes to the IsReadOnly property.
339
- /// </summary>
340
- private static void OnIsReadOnlyChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
305
+ private static void OnPropertyChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
341
306
{
342
- if ( d is TableViewColumn column && column . OwningCollection is { } )
307
+ if ( d is TableViewColumn { OwningCollection : { } } column )
343
308
{
344
- column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( IsReadOnly ) ) ;
309
+ if ( e . Property == CellStyleProperty )
310
+ column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( CellStyle ) ) ;
311
+ else if ( e . Property == WidthProperty )
312
+ column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( Width ) ) ;
313
+ else if ( e . Property == MinWidthProperty )
314
+ column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( MinWidth ) ) ;
315
+ else if ( e . Property == MaxWidthProperty )
316
+ column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( MaxWidth ) ) ;
317
+ else if ( e . Property == ActualWidthProperty )
318
+ column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( ActualWidth ) ) ;
319
+ else if ( e . Property == IsReadOnlyProperty )
320
+ column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( IsReadOnly ) ) ;
321
+ else if ( e . Property == VisibilityProperty )
322
+ column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( Visibility ) ) ;
323
+ else if ( e . Property == OrderProperty )
324
+ column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( Order ) ) ;
345
325
}
346
326
}
347
327
348
328
/// <summary>
349
- /// Handles changes to the Visibility property.
329
+ /// Handles changes to the CanFilter property.
350
330
/// </summary>
351
- private static void OnVisibilityChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
352
- {
353
- if ( d is TableViewColumn column && column . OwningCollection is { } )
354
- {
355
- column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( Visibility ) ) ;
356
- }
357
- }
358
-
359
331
private static void OnCanFilterChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
360
332
{
361
333
if ( d is TableViewColumn column && column . HeaderControl is not null )
@@ -375,17 +347,6 @@ private static void OnHeaderStyleChanged(DependencyObject d, DependencyPropertyC
375
347
}
376
348
}
377
349
378
- /// <summary>
379
- /// Handles changes to the CellStyle property.
380
- /// </summary>
381
- private static void OnCellStyleChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
382
- {
383
- if ( d is TableViewColumn column && column . OwningCollection is { } )
384
- {
385
- column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( CellStyle ) ) ;
386
- }
387
- }
388
-
389
350
/// <summary>
390
351
/// Identifies the HeaderStyle dependency property.
391
352
/// </summary>
@@ -394,7 +355,7 @@ private static void OnCellStyleChanged(DependencyObject d, DependencyPropertyCha
394
355
/// <summary>
395
356
/// Identifies the CellStyle dependency property.
396
357
/// </summary>
397
- public static readonly DependencyProperty CellStyleProperty = DependencyProperty . Register ( nameof ( CellStyle ) , typeof ( Style ) , typeof ( TableViewColumn ) , new PropertyMetadata ( null , OnCellStyleChanged ) ) ;
358
+ public static readonly DependencyProperty CellStyleProperty = DependencyProperty . Register ( nameof ( CellStyle ) , typeof ( Style ) , typeof ( TableViewColumn ) , new PropertyMetadata ( null , OnPropertyChanged ) ) ;
398
359
399
360
/// <summary>
400
361
/// Identifies the Header dependency property.
@@ -404,22 +365,22 @@ private static void OnCellStyleChanged(DependencyObject d, DependencyPropertyCha
404
365
/// <summary>
405
366
/// Identifies the Width dependency property.
406
367
/// </summary>
407
- public static readonly DependencyProperty WidthProperty = DependencyProperty . Register ( nameof ( Width ) , typeof ( GridLength ) , typeof ( TableViewColumn ) , new PropertyMetadata ( GridLength . Auto , OnWidthChanged ) ) ;
368
+ public static readonly DependencyProperty WidthProperty = DependencyProperty . Register ( nameof ( Width ) , typeof ( GridLength ) , typeof ( TableViewColumn ) , new PropertyMetadata ( GridLength . Auto , OnPropertyChanged ) ) ;
408
369
409
370
/// <summary>
410
371
/// Identifies the MinWidth dependency property.
411
372
/// </summary>
412
- public static readonly DependencyProperty MinWidthProperty = DependencyProperty . Register ( nameof ( MinWidth ) , typeof ( double ? ) , typeof ( TableViewColumn ) , new PropertyMetadata ( default , OnMinWidthChanged ) ) ;
373
+ public static readonly DependencyProperty MinWidthProperty = DependencyProperty . Register ( nameof ( MinWidth ) , typeof ( double ? ) , typeof ( TableViewColumn ) , new PropertyMetadata ( default , OnPropertyChanged ) ) ;
413
374
414
375
/// <summary>
415
376
/// Identifies the MaxWidth dependency property.
416
377
/// </summary>
417
- public static readonly DependencyProperty MaxWidthProperty = DependencyProperty . Register ( nameof ( MaxWidth ) , typeof ( double ? ) , typeof ( TableViewColumn ) , new PropertyMetadata ( default , OnMaxWidthChanged ) ) ;
378
+ public static readonly DependencyProperty MaxWidthProperty = DependencyProperty . Register ( nameof ( MaxWidth ) , typeof ( double ? ) , typeof ( TableViewColumn ) , new PropertyMetadata ( default , OnPropertyChanged ) ) ;
418
379
419
380
/// <summary>
420
381
/// Identifies the ActualWidth dependency property.
421
382
/// </summary>
422
- public static readonly DependencyProperty ActualWidthProperty = DependencyProperty . Register ( nameof ( ActualWidth ) , typeof ( double ) , typeof ( TableViewColumn ) , new PropertyMetadata ( 0d , OnActualWidthChanged ) ) ;
383
+ public static readonly DependencyProperty ActualWidthProperty = DependencyProperty . Register ( nameof ( ActualWidth ) , typeof ( double ) , typeof ( TableViewColumn ) , new PropertyMetadata ( 0d , OnPropertyChanged ) ) ;
423
384
424
385
/// <summary>
425
386
/// Identifies the CanResize dependency property.
@@ -429,12 +390,12 @@ private static void OnCellStyleChanged(DependencyObject d, DependencyPropertyCha
429
390
/// <summary>
430
391
/// Identifies the IsReadOnly dependency property.
431
392
/// </summary>
432
- public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty . Register ( nameof ( IsReadOnly ) , typeof ( bool ) , typeof ( TableViewColumn ) , new PropertyMetadata ( false , OnIsReadOnlyChanged ) ) ;
393
+ public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty . Register ( nameof ( IsReadOnly ) , typeof ( bool ) , typeof ( TableViewColumn ) , new PropertyMetadata ( false , OnPropertyChanged ) ) ;
433
394
434
395
/// <summary>
435
396
/// Identifies the Visibility dependency property.
436
397
/// </summary>
437
- public static readonly DependencyProperty VisibilityProperty = DependencyProperty . Register ( nameof ( Visibility ) , typeof ( Visibility ) , typeof ( TableViewColumn ) , new PropertyMetadata ( Visibility . Visible , OnVisibilityChanged ) ) ;
398
+ public static readonly DependencyProperty VisibilityProperty = DependencyProperty . Register ( nameof ( Visibility ) , typeof ( Visibility ) , typeof ( TableViewColumn ) , new PropertyMetadata ( Visibility . Visible , OnPropertyChanged ) ) ;
438
399
439
400
/// <summary>
440
401
/// Identifies the Tag dependency property.
@@ -450,4 +411,9 @@ private static void OnCellStyleChanged(DependencyObject d, DependencyPropertyCha
450
411
/// Identifies the CanFilter dependency property.
451
412
/// </summary>
452
413
public static readonly DependencyProperty CanFilterProperty = DependencyProperty . Register ( nameof ( CanFilter ) , typeof ( bool ) , typeof ( TableViewColumn ) , new PropertyMetadata ( true , OnCanFilterChanged ) ) ;
414
+
415
+ /// <summary>
416
+ /// Identifies the Order dependency property.
417
+ /// </summary>
418
+ public static readonly DependencyProperty OrderProperty = DependencyProperty . Register ( nameof ( Order ) , typeof ( int ? ) , typeof ( TableViewColumn ) , new PropertyMetadata ( null , OnPropertyChanged ) ) ;
453
419
}
0 commit comments