如何解决TabbedPage中的CollectionView不显示数据Xamarin.Forms
这是背景。我有一个TabbedPage视图,其中包含3个ContentPage类型的Views。中间选项卡是一个内容页面,该页面具有一个CollectionView,该View绑定到相应ViewModel中的ObservableCollection。
这是问题所在。当我单击中间选项卡时,CollectionView中没有显示任何数据。我使用断点运行调试,可以看到在实例化Main TabbedPage时已填充了基础的ObservableCollection。选项卡本身中没有显示数据。
If I hit 'Save' on the View in VS,the simulator then refreshes and correctly shows the data. What am I missing? Should I be calling some sort of refresh method when tabs are clicked? Just started working on Xamarin.Forms and teaching myself,so please be gentle.
编辑:对不起,下面添加了代码:我确实看到显示EmptyView字符串,直到我回到VS并在视图上单击“保存”。
这是我的观点:
<RefreshView IsRefreshing="{Binding IsRefreshing}" Command="{Binding RefreshCategoriesCommand}">
<CollectionView ItemsSource="{Binding ProductCategories}"
EmptyView="No products found"
SelectionMode="Single" SelectedItem="{Binding SelectedCategory}" SelectionChangedCommand="{Binding GetCategoryDetailCommand}"
ItemsLayout="VerticalGrid,2" >
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="15" Margin="0,10">
<Grid.RowDefinitions>
<RowDefinition Height="35" />
<RowDefinition Height="35" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70" />
<ColumnDefinition Width="80" />
</Grid.ColumnDefinitions>
<Image Grid.RowSpan="2"
Source="{Binding image.src}"
Aspect="AspectFill"
HeightRequest="60"
WidthRequest="60" />
<Label Grid.Column="1"
Text="{Binding name}"
FontAttributes="Bold"
LineBreakMode="TailTruncation"
VerticalOptions="End" />
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</RefreshView>
ViewModel代码:
public CategoryGroupViewModel(IDialogService dialogService,INavigationService navigationService,IConnectionService connectionService,IWooCommerceRepository wooCommerceRepository)
: base(dialogService,navigationService,connectionService)
{
_wooCommerceRepository = wooCommerceRepository;
GetCategoryDetailCommand = new Command(OnGetCategoryDetail);
RefreshCategoriesCommand = new Command(OnRefreshCategories);
GetCategories();
}
private async void GetCategories()
{
try
{
var categories = await _wooCommerceRepository.GetProductCategories();
ProductCategories = new ObservableCollection<ProductCategory>((IEnumerable<ProductCategory>)categories);
} catch (Exception ex)
{
await _dialogService.ShowDialog("Oops we hit an error " + ex.Message + " " + ex.ToString(),"Error","OK");
}
}
谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。