Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/ColumnFilterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ public virtual void ClearFilter(TableViewColumn? column)

foreach (var col in _tableView.Columns)
{
if (col is not null)
{
col.IsFiltered = false;
}
col?.IsFiltered = false;
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/Columns/TableViewBoundColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace WinUI.TableView;
/// </summary>
public abstract class TableViewBoundColumn : TableViewColumn
{
private Binding _binding = new();

/// <summary>
/// Gets the property path for the binding.
/// </summary>
Expand All @@ -20,10 +18,10 @@ public abstract class TableViewBoundColumn : TableViewColumn
/// </summary>
public virtual Binding Binding
{
get => _binding;
get;
set
{
if (_binding != value)
if (field != value)
{
if (value is not null)
{
Expand All @@ -35,10 +33,10 @@ public virtual Binding Binding
}
}

_binding = value!;
field = value!;
}
}
}
} = new();

/// <summary>
/// Gets or sets the optional data binding used to perform operations on cell content, for example sorting, filtering and exporting.
Expand Down
54 changes: 27 additions & 27 deletions src/Columns/TableViewColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ namespace WinUI.TableView;
[StyleTypedProperty(Property = nameof(CellStyle), StyleTargetType = typeof(TableViewCell))]
public abstract partial class TableViewColumn : DependencyObject
{
private TableViewColumnHeader? _headerControl;
private double _desiredWidth;
private SD? _sortDirection;
private bool _isFiltered;
private bool _isFrozen;
private Func<object, object?>? _funcCompiledPropertyPath;
private Func<object, object?>? _funcCompiledClipboardPropertyPath;
private Binding? _clipboardContentBinding;

/// <summary>
/// Initializes a new instance of the <see cref="TableViewColumn"/> class with default conditional cell styles.
Expand Down Expand Up @@ -244,11 +238,14 @@ public Style CellStyle
/// </summary>
public TableViewColumnHeader? HeaderControl
{
get => _headerControl;
get;
internal set
{
_headerControl = value;
EnsureHeaderStyle();
if (field != value)
{
field = value;
EnsureHeaderStyle();
}
}
}

Expand Down Expand Up @@ -322,12 +319,12 @@ public IList<TableViewConditionalCellStyle> ConditionalCellStyles
/// </summary>
internal double DesiredWidth
{
get => _desiredWidth;
get;
set
{
if (_desiredWidth != value)
if (field != value)
{
_desiredWidth = value;
field = value;
OwningCollection?.HandleColumnPropertyChanged(this, nameof(DesiredWidth));
}
}
Expand All @@ -348,11 +345,14 @@ internal double DesiredWidth
/// </summary>
public SD? SortDirection
{
get => _sortDirection;
get;
set
{
_sortDirection = value;
OnSortDirectionChanged();
if (field != value)
{
field = value;
OnSortDirectionChanged();
}
}
}

Expand All @@ -361,11 +361,14 @@ public SD? SortDirection
/// </summary>
public bool IsFiltered
{
get => _isFiltered;
get;
set
{
_isFiltered = value;
OnIsFilteredChanged();
if (field != value)
{
field = value;
OnIsFilteredChanged();
}
}
}

Expand All @@ -374,12 +377,12 @@ public bool IsFiltered
/// </summary>
public bool IsFrozen
{
get => _isFrozen;
get;
internal set
{
if (_isFrozen != value)
if (field != value)
{
_isFrozen = value;
field = value;
OwningCollection?.HandleColumnPropertyChanged(this, nameof(IsFrozen));
}
}
Expand All @@ -401,8 +404,8 @@ internal set
/// </summary>
public Binding? ClipboardContentBinding
{
get => _clipboardContentBinding ?? OperationContentBinding;
set => _clipboardContentBinding = value;
get => field ?? OperationContentBinding;
set;
}

/// <summary>
Expand Down Expand Up @@ -436,10 +439,7 @@ private void OnIsFilteredChanged()
/// </summary>
internal void EnsureHeaderStyle()
{
if (_headerControl is not null)
{
_headerControl.Style = HeaderStyle ?? TableView?.ColumnHeaderStyle;
}
HeaderControl?.Style = HeaderStyle ?? TableView?.ColumnHeaderStyle;
}

/// <summary>
Expand Down
25 changes: 8 additions & 17 deletions src/Columns/TableViewComboBoxColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ namespace WinUI.TableView;
#endif
public partial class TableViewComboBoxColumn : TableViewBoundColumn
{
private Binding? _textBinding;
private Binding? _selectedValueBinding;

/// <summary>
/// Generates a TextBlock element for the cell.
/// </summary>
Expand Down Expand Up @@ -135,32 +132,26 @@ public bool IsEditable
/// <summary>
/// Gets or sets the binding for the text property of the ComboBox.
/// </summary>
public virtual Binding TextBinding
public virtual Binding? TextBinding
{
get => _textBinding!;
get;
set
{
_textBinding = value;
if (_textBinding is not null)
{
_textBinding.Mode = BindingMode.TwoWay;
}
field = value;
field?.Mode = BindingMode.TwoWay;
}
}

/// <summary>
/// Gets or sets the binding for the selected value property of the ComboBox.
/// </summary>
public virtual Binding SelectedValueBinding
public virtual Binding? SelectedValueBinding
{
get => _selectedValueBinding!;
get;
set
{
_selectedValueBinding = value;
if (_selectedValueBinding is not null)
{
_selectedValueBinding.Mode = BindingMode.TwoWay;
}
field = value;
field?.Mode = BindingMode.TwoWay;
}
}

Expand Down
21 changes: 10 additions & 11 deletions src/Controls/TableViewFilterItemsControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace WinUI.TableView.Controls;
public partial class TableViewFilterItemsControl : UserControl
{
private bool _canSetState = true;
private ICollection<TableViewFilterItem>? _filterItems;

/// <summary>
/// Initializes a new instance of the <see cref="TableViewFilterItemsControl"/> class.
Expand Down Expand Up @@ -93,8 +92,8 @@ internal void SetSelectAllCheckBoxState()
}


selectAllCheckBox.IsChecked = _filterItems?.All(x => x.IsSelected) ?? false ? true
: _filterItems?.All(x => !x.IsSelected) ?? false ? false
selectAllCheckBox.IsChecked = FilterItems?.All(x => x.IsSelected) ?? false ? true
: FilterItems?.All(x => !x.IsSelected) ?? false ? false
: null;
}

Expand All @@ -119,9 +118,9 @@ internal void SetFilterItemsState(bool isSelected)
/// </summary>
private void AttachPropertyChangedHandlers()
{
if (_filterItems?.Count > 0)
if (FilterItems?.Count > 0)
{
foreach (var item in _filterItems)
foreach (var item in FilterItems)
{
item.PropertyChanged += OnFilterItemPropertyChanged;
}
Expand All @@ -133,9 +132,9 @@ private void AttachPropertyChangedHandlers()
/// </summary>
private void DetachPropertyChangedHandlers()
{
if (_filterItems?.Count > 0)
if (FilterItems?.Count > 0)
{
foreach (var item in _filterItems)
foreach (var item in FilterItems)
{
item.PropertyChanged -= OnFilterItemPropertyChanged;
}
Expand All @@ -160,14 +159,14 @@ private void OnFilterItemPropertyChanged(object? sender, PropertyChangedEventArg
/// </summary>
internal ICollection<TableViewFilterItem>? FilterItems
{
get => _filterItems;
get;
set
{
if (_filterItems == value) return;
if (field == value) return;

DetachPropertyChangedHandlers();
_filterItems = value;
filterItemsList.ItemsSource = _filterItems;
field = value;
filterItemsList.ItemsSource = field;
AttachPropertyChangedHandlers();
SetSelectAllCheckBoxState();
}
Expand Down
34 changes: 17 additions & 17 deletions src/ItemsSource/CollectionView.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ partial class CollectionView
/// </summary>
public IEnumerable Source
{
get => _source;
get;
set
{
if (_source == value) return;
if (field == value) return;

DetachCollectionChangedHandlers(_source);
DetachPropertyChangedHandlers(_source);
DetachCollectionChangedHandlers(field);
DetachPropertyChangedHandlers(field);

_source = value;
field = value;

AttachCollectionChangedHandlers(_source);
AttachPropertyChangedHandlers(_source);
AttachCollectionChangedHandlers(field);
AttachPropertyChangedHandlers(field);

CreateItemsCopy(_source);
CreateItemsCopy(field);

HandleSourceChanged();
OnPropertyChanged();
}
}
} = new List<object>();

/// <summary>
/// Gets a value indicating whether this CollectionView can filter its items.
Expand Down Expand Up @@ -81,7 +81,7 @@ public object? CurrentItem
/// <summary>
/// Gets a value indicating whether there are more items to load.
/// </summary>
public bool HasMoreItems => (_source as ISupportIncrementalLoading)?.HasMoreItems ?? false;
public bool HasMoreItems => (Source as ISupportIncrementalLoading)?.HasMoreItems ?? false;

/// <summary>
/// Gets a value indicating whether the current item is after the last item in the view.
Expand All @@ -101,23 +101,23 @@ public object? CurrentItem
/// <summary>
/// Gets a value indicating whether the collection is read-only.
/// </summary>
public bool IsReadOnly => _source == null || _source.IsReadOnly();
public bool IsReadOnly => Source == null || Source.IsReadOnly();

/// <summary>
/// Gets or sets a value indicating whether live shaping is enabled.
/// </summary>
public bool AllowLiveShaping
{
get => _allowLiveShaping;
get;
set
{
if (_allowLiveShaping == value) return;
if (field == value) return;

_allowLiveShaping = value;
if (_allowLiveShaping)
AttachPropertyChangedHandlers(_source);
field = value;
if (field)
AttachPropertyChangedHandlers(Source);
else
DetachPropertyChangedHandlers(_source);
DetachPropertyChangedHandlers(Source);
}
}
}
Loading
Loading