Share via

CollectionView EmptyView does not work

Lloyd Sheen 1,491 Reputation points
2023-11-13T22:32:44.2466667+00:00

This works if all you want is a generic string (no control of fontsize etc.). If you want to have a more complicated view it shows nothing. I have also tried with the code provided in MS Learn but that shows nothing as well.

Developer technologies | .NET | .NET Multi-platform App UI

Answer accepted by question author

Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,166 Reputation points Microsoft External Staff
2023-11-14T05:24:53.21+00:00

Hello,

This is a known issue and the developers are working on a fix, please keep track of EmptyViewTemplate does not do anything #18551.

As a temporary solution, you could put the CollectionView in the RefreshView.

<RefreshView>
    <CollectionView ItemsSource="{Binding Monkeys}"
        Grid.Row="1" MinimumHeightRequest="400">
        <CollectionView.ItemTemplate>
            <DataTemplate>
                <Label Text="tst"/>
            </DataTemplate>
        </CollectionView.ItemTemplate>
        <CollectionView.EmptyView>
            <ContentView>
                <StackLayout HorizontalOptions="CenterAndExpand"
                 VerticalOptions="CenterAndExpand">
                    <Label Text="No results matched your filter."
               Margin="10,25,10,10"
               FontAttributes="Bold"
               FontSize="18"
               HorizontalOptions="Fill"
               HorizontalTextAlignment="Center" />
                    <Label Text="Try a broader filter?"
               FontAttributes="Italic"
               FontSize="12"
               HorizontalOptions="Fill"
               HorizontalTextAlignment="Center" />
                </StackLayout>
            </ContentView>
        </CollectionView.EmptyView>
    </CollectionView>
</RefreshView>

Best Regards,

Alec Liu.


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.