diff --git a/src/WinUI.TableView/TableView.cs b/src/WinUI.TableView/TableView.cs index ac450ec..4455d21 100644 --- a/src/WinUI.TableView/TableView.cs +++ b/src/WinUI.TableView/TableView.cs @@ -341,6 +341,21 @@ private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyC } } + private static void OnAutoGenerateColumnsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is TableView tableView) + { + if (tableView.AutoGenerateColumns) + { + tableView.GenerateColumns(); + } + else + { + tableView.RemoveAutoGeneratedColumns(); + } + } + } + public IAdvancedCollectionView CollectionView { get; private set; } = new AdvancedCollectionView(); internal IDictionary> ActiveFilters { get; } = new Dictionary>(); @@ -381,14 +396,13 @@ public bool AutoGenerateColumns set => SetValue(AutoGenerateColumnsProperty, value); } - public static readonly new DependencyProperty ItemsSourceProperty = DependencyProperty.Register(nameof(ItemsSource), typeof(IList), typeof(TableView), new PropertyMetadata(null, OnItemsSourceChanged)); public static readonly DependencyProperty ColumnsProperty = DependencyProperty.Register(nameof(Columns), typeof(TableViewColumnsColection), typeof(TableView), new PropertyMetadata(null)); public static readonly DependencyProperty RowHeightProperty = DependencyProperty.Register(nameof(RowHeight), typeof(double), typeof(TableView), new PropertyMetadata(40d)); public static readonly DependencyProperty RowMaxHeightProperty = DependencyProperty.Register(nameof(RowMaxHeight), typeof(double), typeof(TableView), new PropertyMetadata(double.PositiveInfinity)); public static readonly DependencyProperty ShowExportOptionsProperty = DependencyProperty.Register(nameof(ShowExportOptions), typeof(bool), typeof(TableView), new PropertyMetadata(false)); - public static readonly DependencyProperty AutoGenerateColumnsProperty = DependencyProperty.Register(nameof(AutoGenerateColumns), typeof(bool), typeof(TableView), new PropertyMetadata(true)); - + public static readonly DependencyProperty AutoGenerateColumnsProperty = DependencyProperty.Register(nameof(AutoGenerateColumns), typeof(bool), typeof(TableView), new PropertyMetadata(true, OnAutoGenerateColumnsChanged)); + public event EventHandler? AutoGeneratingColumn; public event EventHandler? ExportAllRowsContent; public event EventHandler? ExportSelectedRowsContent;