@@ -29,6 +29,7 @@ public partial class TableViewCell : ContentControl
29
29
private ContentPresenter ? _contentPresenter ;
30
30
private Border ? _selectionBorder ;
31
31
private Rectangle ? _v_gridLine ;
32
+ private TableViewCellsPresenter ? _cellPresenter ;
32
33
33
34
/// <summary>
34
35
/// Initializes a new instance of the TableViewCell class.
@@ -43,7 +44,6 @@ public TableViewCell()
43
44
#endif
44
45
}
45
46
46
-
47
47
#if ! WINDOWS
48
48
protected override void OnRightTapped ( RightTappedRoutedEventArgs e )
49
49
{
@@ -84,56 +84,62 @@ protected override void OnApplyTemplate()
84
84
85
85
protected override Size MeasureOverride ( Size availableSize )
86
86
{
87
- if ( Content is FrameworkElement element )
87
+ if ( Column is not null && Row is not null && _contentPresenter is not null && Content is FrameworkElement element )
88
88
{
89
- var v_GridLineStrokeThickness = TableView ? . HeaderGridLinesVisibility is TableViewGridLinesVisibility . All or TableViewGridLinesVisibility . Vertical
90
- || TableView ? . GridLinesVisibility is TableViewGridLinesVisibility . All or TableViewGridLinesVisibility . Vertical
91
- ? TableView . VerticalGridLinesStrokeThickness : 0 ;
89
+ #if WINDOWS
90
+ #region TEMP_FIX_FOR_ISSUE https://github.com/microsoft/microsoft-ui-xaml/issues/9860
91
+ element . MaxWidth = double . PositiveInfinity ;
92
+ element . MaxHeight = double . PositiveInfinity ;
93
+ #endregion
94
+ #endif
95
+ element . Measure ( new Size ( double . PositiveInfinity , double . PositiveInfinity ) ) ;
96
+
97
+ var desiredWidth = element . DesiredSize . Width ;
98
+ desiredWidth += Padding . Left ;
99
+ desiredWidth += Padding . Right ;
100
+ desiredWidth += BorderThickness . Left ;
101
+ desiredWidth += BorderThickness . Right ;
102
+ desiredWidth += _selectionBorder ? . BorderThickness . Right ?? 0 ;
103
+ desiredWidth += _selectionBorder ? . BorderThickness . Left ?? 0 ;
104
+ desiredWidth += _v_gridLine ? . ActualWidth ?? 0d ;
105
+
106
+ Column . DesiredWidth = Math . Max ( Column . DesiredWidth , desiredWidth ) ;
107
+
92
108
#if WINDOWS
93
109
#region TEMP_FIX_FOR_ISSUE https://github.com/microsoft/microsoft-ui-xaml/issues/9860
94
- var contentWidth = Column ? . ActualWidth ?? 0d ;
110
+ var contentWidth = Column . ActualWidth ;
95
111
contentWidth -= element . Margin . Left ;
96
112
contentWidth -= element . Margin . Right ;
97
113
contentWidth -= Padding . Left ;
98
114
contentWidth -= Padding . Right ;
99
115
contentWidth -= BorderThickness . Left ;
100
116
contentWidth -= BorderThickness . Right ;
101
- contentWidth -= _selectionBorder ? . BorderThickness . Right ?? 0 ;
102
117
contentWidth -= _selectionBorder ? . BorderThickness . Left ?? 0 ;
103
- contentWidth -= v_GridLineStrokeThickness ;
104
-
105
- element . MaxWidth = double . PositiveInfinity ;
106
- #endregion
107
- #endif
108
- element . Measure ( new Size ( double . PositiveInfinity , double . PositiveInfinity ) ) ;
109
-
110
- if ( Column is not null )
118
+ contentWidth -= _selectionBorder ? . BorderThickness . Right ?? 0 ;
119
+ contentWidth -= _v_gridLine ? . ActualWidth ?? 0d ;
120
+
121
+ var rowHeight = Row . Height is double . NaN ? double . PositiveInfinity : Row . Height ;
122
+ var rowMaxHeight = Row . MaxHeight ;
123
+ var contentHeight = Math . Min ( rowHeight , rowMaxHeight ) ;
124
+ contentHeight -= element . Margin . Top ;
125
+ contentHeight -= element . Margin . Bottom ;
126
+ contentHeight -= Padding . Top ;
127
+ contentHeight -= Padding . Bottom ;
128
+ contentHeight -= BorderThickness . Top ;
129
+ contentHeight -= BorderThickness . Bottom ;
130
+ contentHeight -= _selectionBorder ? . BorderThickness . Top ?? 0 ;
131
+ contentHeight -= _selectionBorder ? . BorderThickness . Bottom ?? 0 ;
132
+ contentHeight -= GetHorizonalGridlineHeight ( ) ;
133
+
134
+ if ( contentWidth < 0 || contentHeight < 0 )
111
135
{
112
- var desiredWidth = element . DesiredSize . Width ;
113
- desiredWidth += Padding . Left ;
114
- desiredWidth += Padding . Right ;
115
- desiredWidth += BorderThickness . Left ;
116
- desiredWidth += BorderThickness . Right ;
117
- desiredWidth += _selectionBorder ? . BorderThickness . Right ?? 0 ;
118
- desiredWidth += _selectionBorder ? . BorderThickness . Left ?? 0 ;
119
- desiredWidth += v_GridLineStrokeThickness ;
120
-
121
- Column . DesiredWidth = Math . Max ( Column . DesiredWidth , desiredWidth ) ;
136
+ _contentPresenter . Visibility = Visibility . Collapsed ;
122
137
}
123
-
124
- #if WINDOWS
125
- #region TEMP_FIX_FOR_ISSUE https://github.com/microsoft/microsoft-ui-xaml/issues/9860
126
- if ( _contentPresenter is not null )
138
+ else
127
139
{
128
- if ( contentWidth < 0 )
129
- {
130
- _contentPresenter . Visibility = Visibility . Collapsed ;
131
- }
132
- else
133
- {
134
- element . MaxWidth = contentWidth ;
135
- _contentPresenter . Visibility = Visibility . Visible ;
136
- }
140
+ element . MaxWidth = contentWidth ;
141
+ element . MaxHeight = contentHeight ;
142
+ _contentPresenter . Visibility = Visibility . Visible ;
137
143
}
138
144
#endregion
139
145
#endif
@@ -142,6 +148,15 @@ protected override Size MeasureOverride(Size availableSize)
142
148
return base . MeasureOverride ( availableSize ) ;
143
149
}
144
150
151
+ /// <summary>
152
+ /// Retrieves the height of the horizontal gridline.
153
+ /// </summary>
154
+ private double GetHorizonalGridlineHeight ( )
155
+ {
156
+ _cellPresenter ??= this ? . FindAscendant < TableViewCellsPresenter > ( ) ;
157
+ return _cellPresenter ? . GetHorizonalGridlineHeight ( ) ?? 0d ;
158
+ }
159
+
145
160
protected override void OnPointerEntered ( PointerRoutedEventArgs e )
146
161
{
147
162
base . OnPointerEntered ( e ) ;
0 commit comments