@@ -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,70 +84,62 @@ protected override void OnApplyTemplate()
84
84
85
85
protected override Size MeasureOverride ( Size availableSize )
86
86
{
87
- if ( ( Content ?? ContentTemplateRoot ) 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 ;
92
89
#if WINDOWS
93
- #region TEMP_FIX_FOR_ISSUE https://github.com/microsoft/microsoft-ui-xaml/issues/9860
94
- if ( Column is TableViewTemplateColumn )
95
- {
96
- if ( element is ContentControl contentControl &&
97
- ( contentControl . Content ?? contentControl . ContentTemplateRoot ) is FrameworkElement contentElement )
98
- {
99
- element = contentElement ;
100
- }
101
- else
102
- {
103
- return base . MeasureOverride ( availableSize ) ;
104
- }
105
- }
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 ;
106
105
106
+ Column . DesiredWidth = Math . Max ( Column . DesiredWidth , desiredWidth ) ;
107
107
108
- var contentWidth = Column ? . ActualWidth ?? 0d ;
108
+ #if WINDOWS
109
+ #region TEMP_FIX_FOR_ISSUE https://github.com/microsoft/microsoft-ui-xaml/issues/9860
110
+ var contentWidth = Column . ActualWidth ;
109
111
contentWidth -= element . Margin . Left ;
110
112
contentWidth -= element . Margin . Right ;
111
113
contentWidth -= Padding . Left ;
112
114
contentWidth -= Padding . Right ;
113
115
contentWidth -= BorderThickness . Left ;
114
116
contentWidth -= BorderThickness . Right ;
115
- contentWidth -= _selectionBorder ? . BorderThickness . Right ?? 0 ;
116
117
contentWidth -= _selectionBorder ? . BorderThickness . Left ?? 0 ;
117
- contentWidth -= v_GridLineStrokeThickness ;
118
-
119
- element . MaxWidth = double . PositiveInfinity ;
120
- #endregion
121
- #endif
122
- element . Measure ( new Size ( double . PositiveInfinity , double . PositiveInfinity ) ) ;
123
-
124
- 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 )
125
135
{
126
- var desiredWidth = element . DesiredSize . Width ;
127
- desiredWidth += Padding . Left ;
128
- desiredWidth += Padding . Right ;
129
- desiredWidth += BorderThickness . Left ;
130
- desiredWidth += BorderThickness . Right ;
131
- desiredWidth += _selectionBorder ? . BorderThickness . Right ?? 0 ;
132
- desiredWidth += _selectionBorder ? . BorderThickness . Left ?? 0 ;
133
- desiredWidth += v_GridLineStrokeThickness ;
134
-
135
- Column . DesiredWidth = Math . Max ( Column . DesiredWidth , desiredWidth ) ;
136
+ _contentPresenter . Visibility = Visibility . Collapsed ;
136
137
}
137
-
138
- #if WINDOWS
139
- #region TEMP_FIX_FOR_ISSUE https://github.com/microsoft/microsoft-ui-xaml/issues/9860
140
- if ( _contentPresenter is not null )
138
+ else
141
139
{
142
- if ( contentWidth < 0 )
143
- {
144
- _contentPresenter . Visibility = Visibility . Collapsed ;
145
- }
146
- else
147
- {
148
- element . MaxWidth = contentWidth ;
149
- _contentPresenter . Visibility = Visibility . Visible ;
150
- }
140
+ element . MaxWidth = contentWidth ;
141
+ element . MaxHeight = contentHeight ;
142
+ _contentPresenter . Visibility = Visibility . Visible ;
151
143
}
152
144
#endregion
153
145
#endif
@@ -156,6 +148,15 @@ protected override Size MeasureOverride(Size availableSize)
156
148
return base . MeasureOverride ( availableSize ) ;
157
149
}
158
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
+
159
160
protected override void OnPointerEntered ( PointerRoutedEventArgs e )
160
161
{
161
162
base . OnPointerEntered ( e ) ;
0 commit comments