1

I'm trying to change a CollectionView's EmptyView Text's font color. It seems to automatically change from black to white when switching between the native device's Light theme and Dark theme. TextColor is not an attribute, unfortunately.

I'm new to Xamarin.Forms, I'd like to apologize, first, if I haven't displayed enough code, please let me know if there's anything else you need.

My code is located in the AppShell.xaml

<Shell.FlyoutHeaderTemplate>
    <DataTemplate>
        <Grid HeightRequest="{Binding ShellHeight}" 
              ColumnSpacing="0" 
              RowSpacing="0" 
              RowDefinitions="Auto, Auto" 
              ColumnDefinitions="45, Auto">

            <CollectionView 
                   Margin="15,0,0,0" Grid.Row="1" Grid.Column="0" 
                   Grid.ColumnSpan="2" Grid.RowSpan="2" 
                   ItemsSource="{Binding ShellModelList}" 
                   SelectionMode="Single" 
                   EmptyView="No items to display" //<-- trying to change this text's color
                   SelectionChanged="OnCollectionViewSelectionChanged">                   

                <CollectionView.ItemTemplate>                                                                                                                                                            
                    <DataTemplate>
                        <Grid Padding="1" 
                              RowSpacing="10" 
                              ColumnDefinitions="25, Auto" 
                              RowDefinitions="35">

                              <Image Grid.Column="0">
                                  <Image.Source>
                                      <FontImageSource  
                                           x:Name="imgMenuItem" 
                                           FontFamily="{StaticResource NextupFont}" 
                                           Glyph="{Binding IconName}" 
                                           Color="{StaticResource NuCyanBlue}" 
                                           Size="8" />
                                  </Image.Source>
                              </Image>
                             
                            <Label x:Name="lblMenuItem" 
                                   Grid.Column="1" 
                                   Margin="10,0,0,0" 
                                   Text="{Binding Text}" 
                                   TextColor="{AppThemeBinding Light={DynamicResource NuCyanBlue}, Dark={DynamicResource NuBlack}}" 
                                   FontSize="12" 
                                   VerticalTextAlignment="Center" />
                        </Grid>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>
        </Grid>            
    </DataTemplate>
</Shell.FlyoutHeaderTemplate> 

"No Items to Display" is black

"No Items To Display" is white

1
  • 1
    The EmptyView property also can be set to a view, you can custom the label there. For more information, please read the document. Commented Oct 21, 2020 at 6:26

1 Answer 1

3

I think what you should be doing is creating your custom EmptyView.

                    <CollectionView.EmptyView>
                    <StackLayout
                            HorizontalOptions="CenterAndExpand"
                            VerticalOptions="CenterAndExpand">
                            <Label
                                FontAttributes="Bold"
                                FontSize="18"
                                TextColor="Black"
                                HorizontalTextAlignment="Center"
                                Text="No items to display" />
                      </StackLayout>
                   </CollectionView.EmptyView>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.