如何解决更改CollectionView EmptyView文本颜色
我正在尝试更改CollectionView的EmptyView文本的字体颜色。在本机设备的浅色主题和深色主题之间切换时,它似乎会自动从黑色变为白色。不幸的是,TextColor不是属性。
我是Xamarin的新手,我想向您道歉,首先,如果我没有显示足够的代码,请告诉我您是否还有其他需要。
我的代码位于AppShell.xaml
中<Shell.FlyoutHeaderTemplate>
<DataTemplate>
<Grid HeightRequest="{Binding ShellHeight}"
ColumnSpacing="0"
RowSpacing="0"
RowDeFinitions="Auto,Auto"
ColumnDeFinitions="45,Auto">
<CollectionView
Margin="15,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"
Text="{Binding Text}"
TextColor="{AppThemeBinding Light={DynamicResource NuCyanBlue},Dark={DynamicResource NuBlack}}"
FontSize="12"
VerticalTextAlignment="Center" />
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Grid>
</DataTemplate>
</Shell.FlyoutHeaderTemplate>
解决方法
好吧,我认为您应该做的是创建自定义的EmptyView。
<CollectionView.EmptyView>
<StackLayout
HorizontalOptions="CenterAndExpand"
Spacing="15"
VerticalOptions="CenterAndExpand">
<Label
FontAttributes="Bold"
FontSize="18"
TextColor="Black"
HorizontalTextAlignment="Center"
Text="No items to display" />
</StackLayout>
</CollectionView.EmptyView>
祝你好运!如有任何疑问,请随时回来。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。