Skip to content

Commit

Permalink
impelemented AutoGenerate property change handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
w-ahmad committed Apr 20, 2024
1 parent 9798745 commit b177dc5
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/WinUI.TableView/TableView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Predicate<object>> ActiveFilters { get; } = new Dictionary<string, Predicate<object>>();
Expand Down Expand Up @@ -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<TableViewAutoGeneratingColumnEventArgs>? AutoGeneratingColumn;
public event EventHandler<TableViewExportRowsContentEventArgs>? ExportAllRowsContent;
public event EventHandler<TableViewExportRowsContentEventArgs>? ExportSelectedRowsContent;
Expand Down

0 comments on commit b177dc5

Please sign in to comment.