Skip to content

Commit 4c7a3f0

Browse files
committed
fixed virtualization issues with uno apps
1 parent d3c108b commit 4c7a3f0

File tree

5 files changed

+26
-85
lines changed

5 files changed

+26
-85
lines changed

src/TableView.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,16 @@ private void EnsureCellsStyle()
13361336
}
13371337
}
13381338

1339+
#if !WINDOWS
1340+
internal void EnsureCells()
1341+
{
1342+
foreach (var row in _rows)
1343+
{
1344+
row.EnsureCells();
1345+
}
1346+
}
1347+
#endif
1348+
13391349
#if WINDOWS
13401350
/// <summary>
13411351
/// Shows the context flyout for the specified row.

src/TableViewCell.cs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,14 @@ private void OnContextRequested(UIElement sender, ContextRequestedEventArgs args
5656
}
5757
#endif
5858

59-
#if !WINDOWS
60-
protected override void OnDataContextChanged()
61-
{
62-
base.OnDataContextChanged();
63-
64-
if (DataContext is TableViewColumn column)
65-
{
66-
Column = column;
67-
Width = column.ActualWidth;
68-
Style = column.CellStyle ?? TableView?.CellStyle;
69-
}
70-
}
71-
#endif
7259

7360
/// <summary>
7461
/// Handles the Loaded event.
7562
/// </summary>
7663
private void OnLoaded(object sender, RoutedEventArgs e)
7764
{
78-
#if WINDOWS
7965
InvalidateMeasure();
8066
ApplySelectionState();
81-
#endif
8267
}
8368

8469
protected override void OnApplyTemplate()
@@ -89,23 +74,7 @@ protected override void OnApplyTemplate()
8974
_selectionBorder = GetTemplateChild("SelectionBorder") as Border;
9075
_v_gridLine = GetTemplateChild("VerticalGridLine") as Rectangle;
9176

92-
#if WINDOWS
9377
EnsureGridLines();
94-
#else
95-
if (this.FindAscendant<TableViewRow>() is { TableView: { } } row)
96-
{
97-
Row = row;
98-
TableView = row.TableView;
99-
Index = Column is not null ? TableView.Columns.VisibleColumns.IndexOf(Column) : -1;
100-
DataContext = Row?.Content;
101-
102-
EnsureGridLines();
103-
SetElement();
104-
105-
InvalidateMeasure();
106-
ApplySelectionState();
107-
}
108-
#endif
10978
}
11079

11180
protected override Size MeasureOverride(Size availableSize)
@@ -342,10 +311,6 @@ internal async void PrepareForEdit()
342311
/// </summary>
343312
internal void SetElement()
344313
{
345-
#if !WINDOWS
346-
if (_contentPresenter is null) return;
347-
#endif
348-
349314
var element = Column?.GenerateElement(this, Row?.Content);
350315

351316
if (element is not null && Column is TableViewBoundColumn { ElementStyle: { } } boundColumn)

src/TableViewCellsPresenter.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace WinUI.TableView;
1515
public partial class TableViewCellsPresenter : Control
1616
{
1717
private StackPanel? _stackPanel;
18-
private ItemsControl? _itemsControl;
1918
private Rectangle? _v_gridLine;
2019
private Rectangle? _h_gridLine;
2120

@@ -32,21 +31,15 @@ protected override void OnApplyTemplate()
3231
base.OnApplyTemplate();
3332

3433
_stackPanel = GetTemplateChild("StackPanel") as StackPanel;
35-
_itemsControl = GetTemplateChild("ItemsControl") as ItemsControl;
3634
_v_gridLine = GetTemplateChild("VerticalGridLine") as Rectangle;
3735
_h_gridLine = GetTemplateChild("HorizontalGridLine") as Rectangle;
3836

3937
TableViewRow = this.FindAscendant<TableViewRow>();
4038
TableView = TableViewRow?.TableView;
4139

4240
#if !WINDOWS
43-
if (_itemsControl is not null)
44-
{
45-
_itemsControl.Visibility = Visibility.Visible;
46-
_itemsControl.ItemsSource = TableView?.Columns.VisibleColumns;
47-
}
41+
TableView?.EnsureCells();
4842
#endif
49-
5043
EnsureGridLines();
5144
}
5245

@@ -89,13 +82,7 @@ internal void EnsureGridLines()
8982
/// <summary>
9083
/// Gets the list of cells in the presenter.
9184
/// </summary>
92-
public IList<TableViewCell> Cells =>
93-
94-
#if WINDOWS
95-
_stackPanel?.Children.OfType<TableViewCell>().ToList()!;
96-
#else
97-
_itemsControl?.FindDescendants().OfType<TableViewCell>().ToList()!;
98-
#endif
85+
public IList<TableViewCell> Cells => _stackPanel?.Children.OfType<TableViewCell>().ToList()!;
9986

10087
/// <summary>
10188
/// Gets or sets the TableViewRow associated with the presenter.

src/TableViewRow.cs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -227,27 +227,25 @@ protected override void OnTapped(TappedRoutedEventArgs e)
227227
}
228228
}
229229

230-
#if WINDOWS
231230
/// <summary>
232231
/// Ensures cells are created for the row.
233232
/// </summary>
234-
private void EnsureCells()
233+
internal void EnsureCells()
235234
{
236235
if (TableView is null)
237236
{
238237
return;
239238
}
240239

241-
if (CellPresenter is not null)
240+
if (CellPresenter is { Children: { } } && (_ensureCells || _cellPresenter != CellPresenter))
242241
{
242+
_cellPresenter = CellPresenter;
243243
CellPresenter.Children.Clear();
244244

245245
AddCells(TableView.Columns.VisibleColumns);
246-
}
247-
248246
_ensureCells = false;
249247
}
250-
#endif
248+
}
251249

252250
/// <summary>
253251
/// Handles the SizeChanged event.
@@ -561,20 +559,10 @@ internal set
561559
}
562560
}
563561

564-
public TableViewCellsPresenter? CellPresenter
565-
{
566-
get
567-
{
568-
if (_cellPresenter is null)
569-
{
562+
public TableViewCellsPresenter? CellPresenter =>
570563
#if WINDOWS
571-
_cellPresenter = ContentTemplateRoot as TableViewCellsPresenter;
564+
ContentTemplateRoot as TableViewCellsPresenter;
572565
#else
573-
_cellPresenter = this.FindDescendant<TableViewCellsPresenter>();
566+
this.FindDescendant<TableViewCellsPresenter>();
574567
#endif
575-
}
576-
577-
return _cellPresenter;
578-
}
579-
}
580568
}

src/Themes/TableViewCellsPresenter.xaml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,15 @@
2222
<ColumnDefinition Width="Auto" />
2323
<ColumnDefinition Width="*" />
2424
</Grid.ColumnDefinitions>
25+
2526
<StackPanel x:Name="StackPanel"
2627
Grid.Column="1"
27-
Orientation="Horizontal" />
28-
29-
<ItemsControl x:Name="ItemsControl"
30-
Grid.Column="1"
31-
Visibility="Collapsed">
32-
<ItemsControl.ItemsPanel>
33-
<ItemsPanelTemplate>
34-
<StackPanel Orientation="Horizontal" />
35-
</ItemsPanelTemplate>
36-
</ItemsControl.ItemsPanel>
37-
<ItemsControl.ItemTemplate>
38-
<DataTemplate>
39-
<local:TableViewCell />
40-
</DataTemplate>
41-
</ItemsControl.ItemTemplate>
42-
</ItemsControl>
28+
Orientation="Horizontal">
29+
<!--This is just dummy textblock. It would be removed at runtime-->
30+
<TextBlock Margin="16,0"
31+
Text="{Binding}"
32+
VerticalAlignment="Center" />
33+
</StackPanel>
4334

4435
<Rectangle x:Name="VerticalGridLine"
4536
Width="1"

0 commit comments

Comments
 (0)