xamarin.forms - 收藏 View : EmptyView content not shown

标签 xamarin.forms maui

我在使用 ListView 的页面显示中遇到了错误,因此我开始从 ListView 迁移到 Collection View 。 这是带有 Collection View 的 XAML 代码。我不知道为什么 ItemSource 没有任何数据。不显示空 View 。

<StackLayout Style="{StaticResource PageLayout}">
        <StackLayout VerticalOptions="CenterAndExpand" IsVisible="{Binding LoadingIndicator}">
            <ActivityIndicator IsRunning="True" VerticalOptions="Center" HorizontalOptions="Center"/>
        </StackLayout>
        <StackLayout VerticalOptions="FillAndExpand" IsVisible="{Binding ShowContent}">
            <CollectionView ItemsSource="{Binding Items}" VerticalOptions="FillAndExpand" SelectionMode="Single" SelectionChanged="CollectionView_SelectionChanged" Style="{StaticResource CollectionViewChecklistDefault}">
                <CollectionView.Header>
                    <StackLayout HeightRequest="5">
                    </StackLayout>
                </CollectionView.Header>
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                            <Grid ColumnSpacing="0" RowSpacing="0" Margin="0" Padding="0">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="25" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="40" />
                                    <RowDefinition Height="10" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="37*" />
                                    <ColumnDefinition Width="33*" />
                                    <ColumnDefinition Width="30*" />
                                </Grid.ColumnDefinitions>
                                <Label Grid.Row="0" Grid.Column="1" Text="{Binding APP_ID}" IsVisible="False"/>
                                <BoxView Grid.Row="0" Grid.Column="0" Grid.RowSpan="8" Grid.ColumnSpan="3" Style="{StaticResource ListBox}"/>
                                <Image Grid.Row="0" Grid.Column="0" Aspect="AspectFit" Style="{StaticResource ListImage}">
                                    <Image.Source>
                                        <FontImageSource Glyph="&#xf46d;" FontFamily="FontAwesomeSolid" Color="#343a40"></FontImageSource>
                                    </Image.Source>
                                </Image>
                                <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding OBSERVATION_TYPE_NAME}" Style="{StaticResource ListLabelBold}"/>
                                <Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Style="{StaticResource PreviewLabel}">
                                    <Label.FormattedText>
                                        <FormattedString>
                                        <Span Text="{Binding Traductions[DATE], Source={RelativeSource AncestorType={x:Type viewModel:ObservationCloseListViewModel}}, StringFormat='\{0}:'}"  FontAttributes="Bold" TextTransform="Uppercase" TextColor="DarkGray"/>
                                            <Span Text="{Binding OBSERVATION_DATE, StringFormat=' \{0:dd MMM yyyy}'}"/>
                                        </FormattedString>
                                    </Label.FormattedText>
                                </Label>
                                <Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Style="{StaticResource PreviewLabel}">
                                    <Label.FormattedText>
                                        <FormattedString>
                                        <Span Text="{Binding Traductions[COMPANY], Source={RelativeSource AncestorType={x:Type viewModel:ObservationCloseListViewModel}}, StringFormat='\{0}:  '}"  FontAttributes="Bold" TextTransform="Uppercase" TextColor="DarkGray"/>
                                            <Span Text="{Binding COMPANY_NAME, StringFormat=' \{0}'}"/>
                                        </FormattedString>
                                    </Label.FormattedText>
                                </Label>
                                <Label Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" Style="{StaticResource PreviewLabel}">
                                    <Label.FormattedText>
                                        <FormattedString>
                                            <Span Text="{Binding Traductions[WORKPLACE], Source={RelativeSource AncestorType={x:Type viewModel:ObservationCloseListViewModel}}, StringFormat='\{0}:  '}"  FontAttributes="Bold" TextTransform="Uppercase" TextColor="DarkGray"/>
                                            <Span Text="{Binding WORKPLACE_NAME, StringFormat=' \{0}'}"/>
                                        </FormattedString>
                                    </Label.FormattedText>
                                </Label>

                                <Label Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3" Style="{StaticResource PreviewLabel}">
                                    <Label.FormattedText>
                                        <FormattedString>
                                            <Span Text="{Binding Traductions[SECTOR], Source={RelativeSource AncestorType={x:Type viewModel:ObservationCloseListViewModel}}, StringFormat='\{0}:  '}"  FontAttributes="Bold" TextTransform="Uppercase" TextColor="DarkGray"/>
                                            <Span Text="{Binding SECTOR_NAME, StringFormat=' \{0}'}"/>
                                        </FormattedString>
                                    </Label.FormattedText>
                                </Label>

                                <Label Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3" Style="{StaticResource PreviewLabel}">
                                    <Label.FormattedText>
                                        <FormattedString>
                                            <Span Text="{Binding Traductions[FOLLOW_UP_DEPARTMENT], Source={RelativeSource AncestorType={x:Type viewModel:ObservationCloseListViewModel}}, StringFormat='\{0}:  '}"  FontAttributes="Bold" TextTransform="Uppercase" TextColor="DarkGray"/>
                                            <Span Text="{Binding FOLLOW_DEPARTMENT_NAME, StringFormat=' \{0}'}"/>
                                        </FormattedString>
                                    </Label.FormattedText>
                                </Label>
                                <Label Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3" Style="{StaticResource PreviewLabel}">
                                    <Label.FormattedText>
                                        <FormattedString>
                                            <Span Text="{Binding Traductions[DESCRIPTION], Source={RelativeSource AncestorType={x:Type viewModel:ObservationCloseListViewModel}}, StringFormat='\{0}:  '}"  FontAttributes="Bold" TextTransform="Uppercase" TextColor="DarkGray"/>
                                            <Span Text="{Binding OBSERVATION_DESCRIPTION, StringFormat=' \{0}'}"/>
                                        </FormattedString>
                                    </Label.FormattedText>
                                </Label>
                                <Label Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="3"  Text="{Binding Traductions[CLOSE_OBSERVATION], Source={RelativeSource AncestorType={x:Type viewModel:ObservationCloseListViewModel}}}" Style="{StaticResource ListValueGreenEnd}" />
                                <Image Grid.Row="7" Grid.Column="2" Aspect="AspectFit" Style="{StaticResource ListImageArrow}">
                                    <Image.Source>
                                        <FontImageSource Glyph="&#xf138;" FontFamily="FontAwesomeSolid" Color="#7ca04b"></FontImageSource>
                                    </Image.Source>
                                </Image>
                            </Grid>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
                <CollectionView.EmptyView>
                        <StackLayout VerticalOptions="CenterAndExpand">
                            <Label Text="{Binding Traductions[THERE_ARE_NO_OBSERVATIONS], Source={RelativeSource AncestorType={x:Type viewModel:ObservationCloseListViewModel}}}" Style="{StaticResource ListNotItemsFound}"/>
                            <Label Text="TEST"/>
                        </StackLayout>
                </CollectionView.EmptyView>
            </CollectionView>
        </StackLayout>
    </StackLayout>

       

这是它在 Collection View (空)中的显示方式。我加了一个带有 TEST 的额外标签。 enter image description here

事情本来就是这样的。 enter image description here

最佳答案

您遇到的问题的根本原因在于 CollectionView.Header 的使用。但这不是你的错误。这是CollectionView的一个bug:使用Header时不会出现EmptyView。 该问题已报告给 Xamarin.Forms 开发人员。您可以追踪进度here .

关于xamarin.forms - 收藏 View : EmptyView content not shown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70270250/

相关文章:

c# - Xamarin 表格 : Bind byte array to ImageCell ImageSource in ListView

button - Xamarin.Forms:删除按钮内的填充

c# - Xamarin Forms Listview 的条目与自定义选择器冲突

c# - Mobile Blazor Binding 是否类似于在 Razor 模板中使用 XAML 进行编码?

c# - 如何动态更改MAUI OnPlatform资源的值?

sqlite - Xamarin.Forms/Xamarin iOS 中 Akavache 中可能存在的错误

c# - 不同View的ViewModel Initialize方法

c# - .Net maui 中的导航不起作用 - TapgestureRecognizer

ios - 为什么 .net maui 应用程序在 iOS 设备上崩溃?

maui - .net maui ListView 绑定(bind)到 ObservableCollection 时不会滚动到添加的项目