Skip to content

Commit 52c0f11

Browse files
committed
initialize ConditionalCellStyles from constructor
1 parent 551b872 commit 52c0f11

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/Columns/TableViewColumn.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ public abstract partial class TableViewColumn : DependencyObject
2121
private bool _isFrozen;
2222
private Func<object, object?>? _funcCompiledPropertyPath;
2323

24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="TableViewColumn"/> class with default conditional cell styles.
26+
/// </summary>
27+
public TableViewColumn()
28+
{
29+
SetValue(ConditionalCellStylesProperty, new TableViewConditionalCellStylesCollection());
30+
}
31+
2432
/// <summary>
2533
/// Generates a display element for the cell.
2634
/// </summary>
@@ -525,5 +533,5 @@ private static void OnHeaderStyleChanged(DependencyObject d, DependencyPropertyC
525533
/// <summary>
526534
/// Identifies the <see cref="ConditionalCellStyles"/> dependency property.
527535
/// </summary>
528-
public static readonly DependencyProperty ConditionalCellStylesProperty = DependencyProperty.Register(nameof(ConditionalCellStyles), typeof(IList<TableViewConditionalCellStyle>), typeof(TableViewColumn), new PropertyMetadata(new TableViewConditionalCellStylesCollection()));
536+
public static readonly DependencyProperty ConditionalCellStylesProperty = DependencyProperty.Register(nameof(ConditionalCellStyles), typeof(IList<TableViewConditionalCellStyle>), typeof(TableViewColumn), new PropertyMetadata(default));
529537
}

src/TableView.Properties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public partial class TableView
258258
/// <summary>
259259
/// Identifies the <see cref="ConditionalCellStyles"/> dependency property.
260260
/// </summary>
261-
public static readonly DependencyProperty ConditionalCellStylesProperty = DependencyProperty.Register(nameof(ConditionalCellStyles), typeof(IList<TableViewConditionalCellStyle>), typeof(TableView), new PropertyMetadata(new TableViewConditionalCellStylesCollection()));
261+
public static readonly DependencyProperty ConditionalCellStylesProperty = DependencyProperty.Register(nameof(ConditionalCellStyles), typeof(IList<TableViewConditionalCellStyle>), typeof(TableView), new PropertyMetadata(default));
262262

263263
/// <summary>
264264
/// Gets or sets a value indicating whether opening the column filter over header right-click is enabled.

src/TableView.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using CommunityToolkit.WinUI;
2-
using Microsoft.UI;
32
using Microsoft.UI.Xaml;
43
using Microsoft.UI.Xaml.Controls;
54
using Microsoft.UI.Xaml.Controls.Primitives;
@@ -8,6 +7,7 @@
87
using System;
98
using System.Collections;
109
using System.Collections.Generic;
10+
using System.ComponentModel;
1111
using System.ComponentModel.DataAnnotations;
1212
using System.IO;
1313
using System.Linq;
@@ -19,7 +19,6 @@
1919
using Windows.Storage;
2020
using Windows.Storage.Pickers;
2121
using Windows.System;
22-
using WinRT.Interop;
2322
using WinUI.TableView.Extensions;
2423
using WinUI.TableView.Helpers;
2524

@@ -49,10 +48,14 @@ public TableView()
4948

5049
Columns = new TableViewColumnsCollection(this);
5150
FilterHandler = new ColumnFilterHandler(this);
51+
5252
base.ItemsSource = _collectionView;
5353
base.SelectionMode = SelectionMode;
54+
55+
SetValue(ConditionalCellStylesProperty, new TableViewConditionalCellStylesCollection());
5456
RegisterPropertyChangedCallback(ItemsControl.ItemsSourceProperty, OnBaseItemsSourceChanged);
5557
RegisterPropertyChangedCallback(ListViewBase.SelectionModeProperty, OnBaseSelectionModeChanged);
58+
5659
Loaded += OnLoaded;
5760
SelectionChanged += TableView_SelectionChanged;
5861
_collectionView.ItemPropertyChanged += OnItemPropertyChanged;
@@ -88,7 +91,7 @@ private void TableView_SelectionChanged(object sender, SelectionChangedEventArgs
8891
/// <summary>
8992
/// Handles the PropertyChanged event of an item in the TableView.
9093
/// </summary>
91-
private void OnItemPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
94+
private void OnItemPropertyChanged(object? sender, PropertyChangedEventArgs e)
9295
{
9396
var row = ContainerFromItem(sender) as TableViewRow;
9497

@@ -747,8 +750,8 @@ private async Task<StorageFile> GetStorageFile()
747750
var savePicker = new FileSavePicker();
748751
savePicker.FileTypeChoices.Add("CSV (Comma delimited)", [".csv"]);
749752
#if WINDOWS
750-
var hWnd = Win32Interop.GetWindowFromWindowId(XamlRoot.ContentIslandEnvironment.AppWindowId);
751-
InitializeWithWindow.Initialize(savePicker, hWnd);
753+
var hWnd = Microsoft.UI.Win32Interop.GetWindowFromWindowId(XamlRoot.ContentIslandEnvironment.AppWindowId);
754+
WinRT.Interop.InitializeWithWindow.Initialize(savePicker, hWnd);
752755
#endif
753756

754757
return await savePicker.PickSaveFileAsync();

0 commit comments

Comments
 (0)