Skip to content

Commit 7e81f3c

Browse files
committed
fix measure issue when content is not laoded
1 parent 86a7760 commit 7e81f3c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/TableViewCell.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,40 @@ protected override void OnApplyTemplate()
8484
EnsureGridLines();
8585
}
8686

87+
/// <inheritdoc/>
88+
protected override void OnContentChanged(object oldContent, object newContent)
89+
{
90+
base.OnContentChanged(oldContent, newContent);
91+
92+
if (newContent is ContentControl contentControl)
93+
{
94+
contentControl.Loaded += OnContentLoaded;
95+
}
96+
97+
void OnContentLoaded(object sender, RoutedEventArgs e)
98+
{
99+
((ContentControl)sender).Loaded -= OnContentLoaded;
100+
Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
101+
}
102+
}
103+
87104
/// <inheritdoc/>
88105
protected override Size MeasureOverride(Size availableSize)
89106
{
90107
if (Column is not null && Row is not null && _contentPresenter is not null && Content is FrameworkElement element)
91108
{
109+
if (Column is TableViewTemplateColumn)
110+
{
111+
#if WINDOWS
112+
if (element is ContentControl { ContentTemplateRoot: FrameworkElement root })
113+
#else
114+
if (element.FindDescendant<ContentPresenter>() is { ContentTemplateRoot: FrameworkElement root })
115+
#endif
116+
element = root;
117+
else
118+
return base.MeasureOverride(availableSize);
119+
}
120+
92121
#region TEMP_FIX_FOR_ISSUE https://github.com/microsoft/microsoft-ui-xaml/issues/9860
93122
element.MaxWidth = double.PositiveInfinity;
94123
element.MaxHeight = double.PositiveInfinity;

0 commit comments

Comments
 (0)