From 6ebf45ea025b4b55b8303ea2e77328694dc2cac5 Mon Sep 17 00:00:00 2001 From: Waheed Ahmad Date: Sat, 26 Sep 2026 01:14:53 +0500 Subject: [PATCH] refactor: remove GeneratedBindableCustomProperty from library types --- src/Columns/TableViewCheckBoxColumn.cs | 3 -- src/Columns/TableViewColumn.cs | 13 ++++++++- src/Columns/TableViewComboBoxColumn.cs | 16 +++++------ src/Columns/TableViewDateColumn.cs | 31 ++++++++++++++------ src/Columns/TableViewHyperlinkColumn.cs | 3 -- src/Columns/TableViewNumberColumn.cs | 3 -- src/Columns/TableViewTemplateColumn.cs | 3 -- src/Columns/TableViewTextColumn.cs | 3 -- src/Columns/TableViewTimeColumn.cs | 31 ++++++++++++++------ src/Columns/TableViewToggleSwitchColumn.cs | 3 -- src/ItemsSource/TableViewGroupInfo.cs | 24 +++++++++++++--- src/TableView.cs | 4 +-- src/TableViewCell.cs | 3 -- src/TableViewGroupHeaderRow.cs | 16 +++++++++-- src/TableViewHeaderRow.cs | 5 +--- src/TableViewRow.cs | 33 ++++++++++++++++------ src/TableViewRowHeader.cs | 3 -- src/TableViewRowPresenter.cs | 20 +++++++------ tests/TableViewDateColumnTests.cs | 22 +++++++++++++-- tests/TableViewTimeColumnTests.cs | 25 ++++++++++++++-- 20 files changed, 177 insertions(+), 87 deletions(-) diff --git a/src/Columns/TableViewCheckBoxColumn.cs b/src/Columns/TableViewCheckBoxColumn.cs index 56592ad9..782c636c 100644 --- a/src/Columns/TableViewCheckBoxColumn.cs +++ b/src/Columns/TableViewCheckBoxColumn.cs @@ -9,9 +9,6 @@ namespace WinUI.TableView; /// Represents a column in a TableView that displays a CheckBox. /// [StyleTypedProperty(Property = nameof(ElementStyle), StyleTargetType = typeof(CheckBox))] -#if WINDOWS -[WinRT.GeneratedBindableCustomProperty] -#endif public partial class TableViewCheckBoxColumn : TableViewBoundColumn { /// diff --git a/src/Columns/TableViewColumn.cs b/src/Columns/TableViewColumn.cs index c102be29..9b764031 100644 --- a/src/Columns/TableViewColumn.cs +++ b/src/Columns/TableViewColumn.cs @@ -562,6 +562,17 @@ tableView.CurrentCellSlot is not null && } } + /// + /// Handles changes to the Header property. + /// + private static void OnHeaderChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is TableViewColumn column && column.HeaderControl is not null) + { + column.HeaderControl.Content = e.NewValue; + } + } + /// /// Handles changes to the CanFilter property. /// @@ -622,7 +633,7 @@ public string? SortMemberPath /// /// Identifies the Header dependency property. /// - public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(nameof(Header), typeof(object), typeof(TableViewColumn), new PropertyMetadata(null)); + public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(nameof(Header), typeof(object), typeof(TableViewColumn), new PropertyMetadata(null, OnHeaderChanged)); /// /// Identifies the Width dependency property. diff --git a/src/Columns/TableViewComboBoxColumn.cs b/src/Columns/TableViewComboBoxColumn.cs index 18e073dc..56c9fdee 100644 --- a/src/Columns/TableViewComboBoxColumn.cs +++ b/src/Columns/TableViewComboBoxColumn.cs @@ -10,9 +10,6 @@ namespace WinUI.TableView; /// [StyleTypedProperty(Property = nameof(ElementStyle), StyleTargetType = typeof(TextBlock))] [StyleTypedProperty(Property = nameof(EditingElementStyle), StyleTargetType = typeof(ComboBox))] -#if WINDOWS -[WinRT.GeneratedBindableCustomProperty] -#endif public partial class TableViewComboBoxColumn : TableViewBoundColumn { /// @@ -49,12 +46,15 @@ public override FrameworkElement GenerateElement(TableViewCell cell, object? dat /// A ComboBox element. public override FrameworkElement GenerateEditingElement(TableViewCell cell, object? dataItem) { - var comboBox = new ComboBox { HorizontalAlignment = HorizontalAlignment.Stretch }; - comboBox.SetBinding(ItemsControl.ItemsSourceProperty, new Binding { Source = this, Path = new PropertyPath(nameof(ItemsSource)) }); - comboBox.SetBinding(Selector.SelectedValuePathProperty, new Binding { Source = this, Path = new PropertyPath(nameof(SelectedValuePath)) }); - comboBox.SetBinding(ItemsControl.DisplayMemberPathProperty, new Binding { Source = this, Path = new PropertyPath(nameof(DisplayMemberPath)) }); + var comboBox = new ComboBox + { + HorizontalAlignment = HorizontalAlignment.Stretch, + ItemsSource = ItemsSource, + SelectedValuePath = SelectedValuePath, + DisplayMemberPath = DisplayMemberPath, + IsEditable = IsEditable + }; comboBox.SetBinding(Selector.SelectedItemProperty, Binding); - comboBox.SetBinding(ComboBox.IsEditableProperty, new Binding { Source = this, Path = new PropertyPath(nameof(IsEditable)) }); if (TextBinding is not null) { diff --git a/src/Columns/TableViewDateColumn.cs b/src/Columns/TableViewDateColumn.cs index dc3fa334..980d3763 100644 --- a/src/Columns/TableViewDateColumn.cs +++ b/src/Columns/TableViewDateColumn.cs @@ -16,9 +16,6 @@ namespace WinUI.TableView; /// [StyleTypedProperty(Property = nameof(ElementStyle), StyleTargetType = typeof(TextBlock))] [StyleTypedProperty(Property = nameof(EditingElementStyle), StyleTargetType = typeof(TableViewDatePicker))] -#if WINDOWS -[WinRT.GeneratedBindableCustomProperty] -#endif public partial class TableViewDateColumn : TableViewBoundColumn { /// @@ -48,16 +45,21 @@ public override FrameworkElement GenerateElement(TableViewCell cell, object? dat Margin = new Thickness(12, 0, 12, 0), }; + textBlock.SetValue(DateTimeFormatHelper.FormatProperty, DateFormat); textBlock.SetBinding(DateTimeFormatHelper.ValueProperty, Binding); - textBlock.SetBinding(DateTimeFormatHelper.FormatProperty, new Binding - { - Path = new PropertyPath(nameof(DateFormat)), - Source = this - }); return textBlock; } + /// + public override void RefreshElement(TableViewCell cell, object? dataItem) + { + if (cell.Content is TextBlock textBlock) + { + textBlock.SetValue(DateTimeFormatHelper.FormatProperty, DateFormat); + } + } + /// /// Generates a TableViewDatePicker element for editing the cell. /// @@ -263,5 +265,16 @@ public DayOfWeek FirstDayOfWeek /// /// Identifies the DateFormat dependency property. /// - public static readonly DependencyProperty DateFormatProperty = DependencyProperty.Register(nameof(DateFormat), typeof(string), typeof(TableViewDateColumn), new PropertyMetadata("shortdate")); + public static readonly DependencyProperty DateFormatProperty = DependencyProperty.Register(nameof(DateFormat), typeof(string), typeof(TableViewDateColumn), new PropertyMetadata("shortdate", OnDateFormatChanged)); + + /// + /// Handles changes to the DateFormat property. + /// + private static void OnDateFormatChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is TableViewDateColumn column) + { + column.OwningCollection?.HandleColumnPropertyChanged(column, nameof(DateFormat)); + } + } } diff --git a/src/Columns/TableViewHyperlinkColumn.cs b/src/Columns/TableViewHyperlinkColumn.cs index 7c408bc2..5431e19b 100644 --- a/src/Columns/TableViewHyperlinkColumn.cs +++ b/src/Columns/TableViewHyperlinkColumn.cs @@ -9,9 +9,6 @@ namespace WinUI.TableView; /// [StyleTypedProperty(Property = nameof(ElementStyle), StyleTargetType = typeof(HyperlinkButton))] [StyleTypedProperty(Property = nameof(EditingElementStyle), StyleTargetType = typeof(TextBox))] -#if WINDOWS -[WinRT.GeneratedBindableCustomProperty] -#endif public partial class TableViewHyperlinkColumn : TableViewTextColumn { /// diff --git a/src/Columns/TableViewNumberColumn.cs b/src/Columns/TableViewNumberColumn.cs index 9c93fab3..4791e97c 100644 --- a/src/Columns/TableViewNumberColumn.cs +++ b/src/Columns/TableViewNumberColumn.cs @@ -9,9 +9,6 @@ namespace WinUI.TableView; /// [StyleTypedProperty(Property = nameof(ElementStyle), StyleTargetType = typeof(TextBlock))] [StyleTypedProperty(Property = nameof(EditingElementStyle), StyleTargetType = typeof(NumberBox))] -#if WINDOWS -[WinRT.GeneratedBindableCustomProperty] -#endif public partial class TableViewNumberColumn : TableViewBoundColumn { /// diff --git a/src/Columns/TableViewTemplateColumn.cs b/src/Columns/TableViewTemplateColumn.cs index 044fc192..63e66e6c 100644 --- a/src/Columns/TableViewTemplateColumn.cs +++ b/src/Columns/TableViewTemplateColumn.cs @@ -7,9 +7,6 @@ namespace WinUI.TableView; /// /// Represents a column in a TableView that uses a DataTemplate for its content. /// -#if WINDOWS -[WinRT.GeneratedBindableCustomProperty] -#endif [ContentProperty(Name = nameof(CellTemplate))] public partial class TableViewTemplateColumn : TableViewColumn { diff --git a/src/Columns/TableViewTextColumn.cs b/src/Columns/TableViewTextColumn.cs index dca276ea..84ca5c7e 100644 --- a/src/Columns/TableViewTextColumn.cs +++ b/src/Columns/TableViewTextColumn.cs @@ -8,9 +8,6 @@ namespace WinUI.TableView; /// [StyleTypedProperty(Property = nameof(ElementStyle), StyleTargetType = typeof(TextBlock))] [StyleTypedProperty(Property = nameof(EditingElementStyle), StyleTargetType = typeof(TextBox))] -#if WINDOWS -[WinRT.GeneratedBindableCustomProperty] -#endif public partial class TableViewTextColumn : TableViewBoundColumn { /// diff --git a/src/Columns/TableViewTimeColumn.cs b/src/Columns/TableViewTimeColumn.cs index e8899a1f..c040f8db 100644 --- a/src/Columns/TableViewTimeColumn.cs +++ b/src/Columns/TableViewTimeColumn.cs @@ -13,9 +13,6 @@ namespace WinUI.TableView; /// [StyleTypedProperty(Property = nameof(ElementStyle), StyleTargetType = typeof(TextBlock))] [StyleTypedProperty(Property = nameof(EditingElementStyle), StyleTargetType = typeof(TableViewTimePicker))] -#if WINDOWS -[WinRT.GeneratedBindableCustomProperty] -#endif public partial class TableViewTimeColumn : TableViewBoundColumn { /// @@ -44,16 +41,21 @@ public override FrameworkElement GenerateElement(TableViewCell cell, object? dat Margin = new Thickness(12, 0, 12, 0), }; + textBlock.SetValue(DateTimeFormatHelper.FormatProperty, ClockIdentifier); textBlock.SetBinding(DateTimeFormatHelper.ValueProperty, Binding); - textBlock.SetBinding(DateTimeFormatHelper.FormatProperty, new Binding - { - Path = new PropertyPath(nameof(ClockIdentifier)), - Source = this - }); return textBlock; } + /// + public override void RefreshElement(TableViewCell cell, object? dataItem) + { + if (cell.Content is TextBlock textBlock) + { + textBlock.SetValue(DateTimeFormatHelper.FormatProperty, ClockIdentifier); + } + } + /// /// Generates a TableViewTimePicker element for editing the cell. /// @@ -165,7 +167,18 @@ public string? PlaceholderText /// /// Identifies the ClockIdentifier dependency property. /// - public static readonly DependencyProperty ClockIdentifierProperty = DependencyProperty.Register(nameof(ClockIdentifier), typeof(string), typeof(TableViewTimeColumn), new PropertyMetadata(default)); + public static readonly DependencyProperty ClockIdentifierProperty = DependencyProperty.Register(nameof(ClockIdentifier), typeof(string), typeof(TableViewTimeColumn), new PropertyMetadata(default, OnClockIdentifierChanged)); + + /// + /// Handles changes to the ClockIdentifier property. + /// + private static void OnClockIdentifierChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is TableViewTimeColumn column) + { + column.OwningCollection?.HandleColumnPropertyChanged(column, nameof(ClockIdentifier)); + } + } /// /// Identifies the PlaceholderText dependency property. diff --git a/src/Columns/TableViewToggleSwitchColumn.cs b/src/Columns/TableViewToggleSwitchColumn.cs index 60213979..54fab2c0 100644 --- a/src/Columns/TableViewToggleSwitchColumn.cs +++ b/src/Columns/TableViewToggleSwitchColumn.cs @@ -8,9 +8,6 @@ namespace WinUI.TableView; /// Represents a column in a TableView that displays a ToggleSwitch. /// [StyleTypedProperty(Property = nameof(ElementStyle), StyleTargetType = typeof(ToggleSwitch))] -#if WINDOWS -[WinRT.GeneratedBindableCustomProperty] -#endif public partial class TableViewToggleSwitchColumn : TableViewBoundColumn { /// diff --git a/src/ItemsSource/TableViewGroupInfo.cs b/src/ItemsSource/TableViewGroupInfo.cs index 69566a1a..929be4e1 100644 --- a/src/ItemsSource/TableViewGroupInfo.cs +++ b/src/ItemsSource/TableViewGroupInfo.cs @@ -1,6 +1,5 @@ #if WINDOWS using Microsoft.UI.Xaml; -using WinRT; namespace WinUI.TableView; @@ -9,7 +8,6 @@ namespace WinUI.TableView; /// count, nesting level, and expanded/collapsed state. This is the object bound as a 's /// . /// -[GeneratedBindableCustomProperty] public partial class TableViewGroupInfo : DependencyObject { @@ -40,12 +38,20 @@ private static void OnIsExpandedChanged(DependencyObject d, DependencyPropertyCh /// /// Gets the group's key, e.g. the value of the column/property being grouped by. /// - public object? Key { get; init; } + public object? Key + { + get => GetValue(KeyProperty); + init => SetValue(KeyProperty, value); + } /// /// Gets the number of items in this group (including all descendant subgroups/items, if any). /// - public int Count { get; init; } + public int Count + { + get => (int)GetValue(CountProperty); + init => SetValue(CountProperty, value); + } /// /// Gets the zero-based nesting level of this group among the active entries. @@ -62,6 +68,16 @@ public bool IsExpanded set => SetValue(IsExpandedProperty, value); } + /// + /// Identifies the dependency property. + /// + public static readonly DependencyProperty KeyProperty = DependencyProperty.Register(nameof(Key), typeof(object), typeof(TableViewGroupInfo), new PropertyMetadata(null)); + + /// + /// Identifies the dependency property. + /// + public static readonly DependencyProperty CountProperty = DependencyProperty.Register(nameof(Count), typeof(int), typeof(TableViewGroupInfo), new PropertyMetadata(0)); + /// /// Identifies the dependency property. /// diff --git a/src/TableView.cs b/src/TableView.cs index e7c9ceb4..879b295b 100644 --- a/src/TableView.cs +++ b/src/TableView.cs @@ -282,8 +282,8 @@ protected override DependencyObject GetContainerForItemOverride() var row = new TableViewRow { TableView = this }; // Set bindings for FontFamily and FontSize to propagate from TableView to TableViewRow - row.SetBinding(FontFamilyProperty, new Binding { Path = new("TableView.FontFamily"), RelativeSource = new() { Mode = RelativeSourceMode.Self } }); - row.SetBinding(FontSizeProperty, new Binding { Path = new("TableView.FontSize"), RelativeSource = new() { Mode = RelativeSourceMode.Self } }); + row.SetBinding(FontFamilyProperty, new Binding { Path = new(nameof(FontFamily)), Source = this }); + row.SetBinding(FontSizeProperty, new Binding { Path = new(nameof(FontSize)), Source = this }); _rows.Add(row); return row; diff --git a/src/TableViewCell.cs b/src/TableViewCell.cs index 9463bbc8..ae956f9d 100644 --- a/src/TableViewCell.cs +++ b/src/TableViewCell.cs @@ -20,9 +20,6 @@ namespace WinUI.TableView; [TemplateVisualState(Name = VisualStates.StateCurrent, GroupName = VisualStates.GroupCurrent)] [TemplateVisualState(Name = VisualStates.StateSelected, GroupName = VisualStates.GroupSelection)] [TemplateVisualState(Name = VisualStates.StateUnselected, GroupName = VisualStates.GroupSelection)] -#if WINDOWS -[WinRT.GeneratedBindableCustomProperty] -#endif public partial class TableViewCell : ContentControl { private ContentPresenter? _contentPresenter; diff --git a/src/TableViewGroupHeaderRow.cs b/src/TableViewGroupHeaderRow.cs index f4c685f6..88756040 100644 --- a/src/TableViewGroupHeaderRow.cs +++ b/src/TableViewGroupHeaderRow.cs @@ -38,6 +38,16 @@ public TableViewGroupHeaderRow() /// internal TableView? TableView { get; set; } + /// + /// Gets the this row is the header for. + /// + /// + /// Exposing it here also puts in the XAML type metadata generated for this + /// library, which is what lets {Binding Key}/{Binding Count} in a group header template resolve + /// under trimming/Native AOT without the type needing WinRT.GeneratedBindableCustomProperty. + /// + public TableViewGroupInfo? GroupInfo => Content as TableViewGroupInfo; + /// protected override void OnApplyTemplate() { @@ -52,7 +62,7 @@ protected override void OnApplyTemplate() EnsureGridLines(); UpdateExpandCollapseButtonVisibility(); - if (Content is TableViewGroupInfo groupInfo) + if (GroupInfo is { } groupInfo) { UpdateExpandCollapseVisualState(groupInfo.IsExpanded); } @@ -101,7 +111,7 @@ internal void UpdateExpandCollapseButtonVisibility() /// private void OnExpandCollapseButtonClick(object sender, RoutedEventArgs e) { - if (Content is TableViewGroupInfo groupInfo) + if (GroupInfo is { } groupInfo) { groupInfo.IsExpanded = !groupInfo.IsExpanded; UpdateExpandCollapseVisualState(groupInfo.IsExpanded); @@ -113,7 +123,7 @@ protected override void OnContentChanged(object oldContent, object newContent) { base.OnContentChanged(oldContent, newContent); - if (Content is TableViewGroupInfo groupInfo) + if (GroupInfo is { } groupInfo) { _indentPlaceholder?.Width = groupInfo.Level * GroupIndentSize; UpdateExpandCollapseVisualState(groupInfo.IsExpanded); diff --git a/src/TableViewHeaderRow.cs b/src/TableViewHeaderRow.cs index 11c76636..349891d5 100644 --- a/src/TableViewHeaderRow.cs +++ b/src/TableViewHeaderRow.cs @@ -255,13 +255,10 @@ private void AddHeaders(IEnumerable columns) { foreach (var column in columns) { - var header = new TableViewColumnHeader { DataContext = column, Column = column }; + var header = new TableViewColumnHeader { DataContext = column, Column = column, Content = column.Header }; column.HeaderControl = header; InsertHeader(header); - - header.SetBinding(ContentControl.ContentProperty, - new Binding { Path = new PropertyPath(nameof(TableViewColumn.Header)) }); } CalculateHeaderWidths(); diff --git a/src/TableViewRow.cs b/src/TableViewRow.cs index e607dfc6..8d45100f 100644 --- a/src/TableViewRow.cs +++ b/src/TableViewRow.cs @@ -22,9 +22,6 @@ namespace WinUI.TableView; /// Represents a row in a TableView. /// -#if WINDOWS -[WinRT.GeneratedBindableCustomProperty] -#endif public partial class TableViewRow : ListViewItem { private const string Selection_Background = "SelectionBackground"; @@ -335,6 +332,24 @@ e.PropertyName is nameof(TableViewColumn.IsFrozen)) && { EnsureEditingElementStyle(e.Column); } + else if (e.PropertyName is nameof(TableViewDateColumn.DateFormat) or nameof(TableViewTimeColumn.ClockIdentifier)) + { + RefreshElements(e.Column); + } + } + + /// + /// Refreshes the elements of the cells for the specified column. + /// + private void RefreshElements(TableViewColumn column) + { + foreach (var cell in Cells) + { + if (cell.Column == column) + { + cell.RefreshElement(); + } + } } /// @@ -375,20 +390,20 @@ private void AddCells(IEnumerable columns) cell.SetBinding(HeightProperty, new Binding { - Path = new PropertyPath($"{nameof(TableViewCell.TableView)}.{nameof(TableView.RowHeight)}"), - RelativeSource = new RelativeSource { Mode = RelativeSourceMode.Self } + Path = new PropertyPath(nameof(TableView.RowHeight)), + Source = TableView }); cell.SetBinding(MaxHeightProperty, new Binding { - Path = new PropertyPath($"{nameof(TableViewCell.TableView)}.{nameof(TableView.RowMaxHeight)}"), - RelativeSource = new RelativeSource { Mode = RelativeSourceMode.Self } + Path = new PropertyPath(nameof(TableView.RowMaxHeight)), + Source = TableView }); cell.SetBinding(MinHeightProperty, new Binding { - Path = new PropertyPath($"{nameof(TableViewCell.TableView)}.{nameof(TableView.RowMinHeight)}"), - RelativeSource = new RelativeSource { Mode = RelativeSourceMode.Self } + Path = new PropertyPath(nameof(TableView.RowMinHeight)), + Source = TableView }); RowPresenter.InsertCell(cell); diff --git a/src/TableViewRowHeader.cs b/src/TableViewRowHeader.cs index 82805719..b92656c4 100644 --- a/src/TableViewRowHeader.cs +++ b/src/TableViewRowHeader.cs @@ -10,9 +10,6 @@ namespace WinUI.TableView; /// /// Represents a header for row in TableView. /// -#if WINDOWS -[WinRT.GeneratedBindableCustomProperty] -#endif public partial class TableViewRowHeader : ContentControl { private ContentPresenter? _contentPresenter; diff --git a/src/TableViewRowPresenter.cs b/src/TableViewRowPresenter.cs index c1812c17..c8e2f17d 100644 --- a/src/TableViewRowPresenter.cs +++ b/src/TableViewRowPresenter.cs @@ -361,22 +361,24 @@ internal void SetRowHeaderVisibility() internal void SetRowHeaderBindings() { - _rowHeader?.SetBinding(HeightProperty, new Binding + if (_rowHeader is null || TableView is null) return; + + _rowHeader.SetBinding(HeightProperty, new Binding { - Path = new PropertyPath($"{nameof(TableViewRowHeader.TableView)}.{nameof(TableView.RowHeight)}"), - RelativeSource = new RelativeSource { Mode = RelativeSourceMode.Self } + Path = new PropertyPath(nameof(TableView.RowHeight)), + Source = TableView }); - _rowHeader?.SetBinding(MaxHeightProperty, new Binding + _rowHeader.SetBinding(MaxHeightProperty, new Binding { - Path = new PropertyPath($"{nameof(TableViewRowHeader.TableView)}.{nameof(TableView.RowMaxHeight)}"), - RelativeSource = new RelativeSource { Mode = RelativeSourceMode.Self } + Path = new PropertyPath(nameof(TableView.RowMaxHeight)), + Source = TableView }); - _rowHeader?.SetBinding(MinHeightProperty, new Binding + _rowHeader.SetBinding(MinHeightProperty, new Binding { - Path = new PropertyPath($"{nameof(TableViewRowHeader.TableView)}.{nameof(TableView.RowMinHeight)}"), - RelativeSource = new RelativeSource { Mode = RelativeSourceMode.Self } + Path = new PropertyPath(nameof(TableView.RowMinHeight)), + Source = TableView }); } diff --git a/tests/TableViewDateColumnTests.cs b/tests/TableViewDateColumnTests.cs index e4a83ae1..682968b4 100644 --- a/tests/TableViewDateColumnTests.cs +++ b/tests/TableViewDateColumnTests.cs @@ -47,7 +47,7 @@ public void TableViewDateColumn_GeneratesEditingElementWithConfiguredProperties( } [UITestMethod] - public void TableViewDateColumn_GeneratesDisplayElement_WithFormatBindings() + public void TableViewDateColumn_GeneratesDisplayElement_WithValueBindingAndFormat() { var column = new TableViewDateColumn { @@ -58,10 +58,28 @@ public void TableViewDateColumn_GeneratesDisplayElement_WithFormatBindings() var element = (TextBlock)column.GenerateElement(new TableViewCell(), new ColumnTestItem()); Assert.IsNotNull(element.GetBindingExpression(DateTimeFormatHelper.ValueProperty)); - Assert.IsNotNull(element.GetBindingExpression(DateTimeFormatHelper.FormatProperty)); + Assert.AreEqual("shortdate", DateTimeFormatHelper.GetFormat(element)); Assert.AreEqual(new Thickness(12, 0, 12, 0), element.Margin); } + [UITestMethod] + public void TableViewDateColumn_RefreshElement_AppliesUpdatedDateFormat() + { + var column = new TableViewDateColumn + { + Binding = new Binding { Path = new PropertyPath(nameof(ColumnTestItem.DueDate)) }, + DateFormat = "shortdate" + }; + var cell = new TableViewCell(); + var element = (TextBlock)column.GenerateElement(cell, new ColumnTestItem()); + cell.Content = element; + + column.DateFormat = "longdate"; + column.RefreshElement(cell, new ColumnTestItem()); + + Assert.AreEqual("longdate", DateTimeFormatHelper.GetFormat(element)); + } + [UITestMethod] public void TableViewDateColumn_UsesCustomPlaceholderAndDateTimeOffsetFallback() { diff --git a/tests/TableViewTimeColumnTests.cs b/tests/TableViewTimeColumnTests.cs index 70b26e7e..b1ed20ae 100644 --- a/tests/TableViewTimeColumnTests.cs +++ b/tests/TableViewTimeColumnTests.cs @@ -38,20 +38,39 @@ public void TableViewTimeColumn_GeneratesEditingElementWithConfiguredProperties( } [UITestMethod] - public void TableViewTimeColumn_GeneratesDisplayElement_WithFormatBindings() + public void TableViewTimeColumn_GeneratesDisplayElement_WithValueBindingAndFormat() { var column = new TableViewTimeColumn { - Binding = new Binding { Path = new PropertyPath(nameof(ColumnTestItem.AppointmentTime)) } + Binding = new Binding { Path = new PropertyPath(nameof(ColumnTestItem.AppointmentTime)) }, + ClockIdentifier = "24HourClock" }; var element = (TextBlock)column.GenerateElement(new TableViewCell(), new ColumnTestItem()); Assert.IsNotNull(element.GetBindingExpression(DateTimeFormatHelper.ValueProperty)); - Assert.IsNotNull(element.GetBindingExpression(DateTimeFormatHelper.FormatProperty)); + Assert.AreEqual("24HourClock", DateTimeFormatHelper.GetFormat(element)); Assert.AreEqual(new Thickness(12, 0, 12, 0), element.Margin); } + [UITestMethod] + public void TableViewTimeColumn_RefreshElement_AppliesUpdatedClockIdentifier() + { + var column = new TableViewTimeColumn + { + Binding = new Binding { Path = new PropertyPath(nameof(ColumnTestItem.AppointmentTime)) }, + ClockIdentifier = "12HourClock" + }; + var cell = new TableViewCell(); + var element = (TextBlock)column.GenerateElement(cell, new ColumnTestItem()); + cell.Content = element; + + column.ClockIdentifier = "24HourClock"; + column.RefreshElement(cell, new ColumnTestItem()); + + Assert.AreEqual("24HourClock", DateTimeFormatHelper.GetFormat(element)); + } + [UITestMethod] public void TableViewTimeColumn_UsesCustomPlaceholderAndTimeSpanFallback() {