Изучение MAUI, исходя из ограниченного опыта работы с WPF.
У меня есть CollectionView с двумя столбцами данных. Я хочу поместить заголовок в каждый столбец данных. Следующий код не показывает никаких заголовков
<CollectionView EmptyView = "No data available" HorizontalOptions = "Center" HeightRequest = "150" ItemsSource = "{Binding PropertyDetails}" >
<CollectionView.Header>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width = "Auto" />
<ColumnDefinition Width = "*" />
</Grid.ColumnDefinitions>
<Label Text = "Address" Grid.Column = "0"/>
<Label Text = "Cost" Grid.Column = "1"/>
</Grid>
</CollectionView.Header>
The following code snips do show a header
<CollectionView EmptyView = "No data available" HorizontalOptions = "Center" HeightRequest = "150" ItemsSource = "{Binding PropertyDetails}" Header = "My header">```
OR
<CollectionView.Header>
My Header
</CollectionView.Header>
but this only gives me a simple unformattable header for the whole collectionview and not for each column of data.
I have read a couple of posts on SO and google put they don't quite fit my issue.
I have also tried with a CollectionView.HeaderTemplate but that failed as well
Ideally I want to get better formatting for the headers but for now I will be glad to get them visible.
What, if anything have I missed?
Many thanks
Kevin





На Android и iOS свойство HeaderTemplate может быть установлено для DataTemplate объектов, которые используются для форматирования заголовка. В этом случае свойство Header должно быть привязано к текущему источнику для применения шаблонов, как показано в следующем примере:
<CollectionView Header = "{Binding .}"
ItemsSource = "{Binding Monkeys}"
ItemsLayout = "VerticalGrid, 2">
<CollectionView.HeaderTemplate>
<DataTemplate>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width = "*" />
<ColumnDefinition Width = "*" />
</Grid.ColumnDefinitions>
<Label Grid.Column = "0" Margin = "10,0,0,0"
Text = "Address" BackgroundColor = "LightGray"
FontSize = "12" FontAttributes = "Bold"/>
<Label Grid.Column = "1" Margin = "10,0,0,0"
Text = "Cost" BackgroundColor = "LightGray"
FontSize = "12" FontAttributes = "Bold"/>
</Grid>
</DataTemplate>
</CollectionView.HeaderTemplate>
//Omitted for brevity
На Winodws есть известная проблема:Заголовок и нижний колонтитул CollectionView не показывает #14557 при отображении заголовка вы можете следить там: https://github.com/dotnet/maui/issues/14557.
Выход:
Привет Александр. Спасибо за ответ. Я отметил это как ответ. Это действительно нужно для работы в Windows, поэтому, думаю, мне придется подождать, пока известная проблема не будет решена. еще раз спасибо
попробуйте присвоить сетке высоту