WPF中是否有PagedCollectionView的实现?它存在于Silverlight中但不在WPF中.
如果没有,实现这个最简单的方法是什么?
当<Label Content="{Binding ItemCount}"/>
我的 View 上有一个绑定到 ViewModel 上的属性时。
在视图模型上,我将属性定义为
public int ItemCount
{
get { RowViewModelsCollectionView.Count; }
}
Run Code Online (Sandbox Code Playgroud)
我清楚地要求对 进行计数CollectionView
,我希望在其中获得仅可见项目的计数。不幸的是,我得到了整行的计数,即使是那些由于过滤器而没有显示在视图上的行。
更新:
在科尔:
RowViewModelsCollectionView= new ListCollectionView(rowViewModels) {Filter = Contains};
private bool Contains(object obj)
{
RowViewModel rowViewModel = obj as RowViewModel;
if (rowViewModel != null && Books.ContainsKey(rowViewModel.Book))
{
RaisePropertyChanged("ItemCount"); // Trying out to raise it without joy
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我应该如何解决这个问题?
使用我的自定义UICollectionViewLayout
子类时,cellForItemAtIndexPath:
不会调用(我使用断点和调试输出检查).这是我使用自定义布局的方式:
- (void)viewDidLoad
{
[super viewDidLoad];
DMSGridLayout* gridLayout = [[DMSGridLayout alloc] init];
// UICollectionViewFlowLayout* flow = [[UICollectionViewFlowLayout alloc] init];
// [flow setItemSize:CGSizeMake(150, 150)];
UICollectionView *collection = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:gridLayout];
collection.delegate = self;
collection.dataSource = self;
self.collectionView = collection;
[self.view addSubview:self.collectionView];
[self.collectionView registerClass:[DMSGridCell class] forCellWithReuseIdentifier:@"CollectionCell"];
}
Run Code Online (Sandbox Code Playgroud)
但是当我更改上面的代码UICollectionViewFlowLayout
而不是我的自定义子类时,cellForItemAtIndexPath:
就会被调用.
可能是我的自定义布局子类中的某些代码无法cellForItemAtIndexPath
被调用吗?
我正在iOS中构建一个应用程序,我希望我的CollectionView中的单元格在触摸时突出显示,就像普通按钮一样.如何在didSelectItemAtIndexPath:(NSIndexPath*)indexPath方法中实现此目的?
所以我正在使用UICollectionView
under AutoLayout
-enabled storyboard.我正在尝试根据collectionView
自身设置单元格大小,它基于[collectionView: layout: sizeForItemAtIndexPath:]
方法.
collectionView
也取决于自动布局,它第一次给出错误的大小(我假设这是在视图布局之前).我知道在viewDidLayoutSubviews
调用方法后它们将具有正确的大小,但是它会导致collectionView
项目的双重重载,这会在运行时产生UI故障.
这是[collectionView: layout: sizeForItemAtIndexPath:]
我实施的方法.
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGSize innerSize = CGSizeMake(galleryView.frame.size.width - 80, galleryView.frame.size.height - 40);
GLPhotoAsset *photo = [(PCOpticsPhotoPoint *)_cluster.points[indexPath.row] photo];
CGFloat ratio = MIN(innerSize.width / photo.size.width, innerSize.height / photo.size.height);
return CGSizeMake(photo.size.width * ratio, photo.size.height * ratio);
}
Run Code Online (Sandbox Code Playgroud) 我有一个 UICollectionView,它固定到顶部布局指南(我使用 NavigationController 因此它固定到导航栏)并与它覆盖的图像底部对齐。
我隐藏了导航栏并为图像位置设置了动画,这意味着由于限制,CollectionView 也在移动。
在我的 scrollView 的 scrollViewDidScroll 委托方法中,我正在为它们设置动画:
if scrollView.panGestureRecognizer.translation(in: scrollView).y > 0 {
//scrolling up
navigationController?.setNavigationBarHidden(false, animated: true)
UIView.animate(withDuration: 0.2, animations: {
self.topImageContraintToTop.constant = 0
self.view.layoutIfNeeded()
})
} else {
//scrolling down
navigationController?.setNavigationBarHidden(true, animated: true)
UIView.animate(withDuration: 0.2, animations: {
self.topImageContraintToTop.constant = -(self.navigationController?.navigationBar.bounds.size.height)! - 10
self.view.layoutIfNeeded()
})
}
Run Code Online (Sandbox Code Playgroud)
因此,每次发生此动画时,CollectionView 的可见单元格都会短暂闪烁/闪烁。
我已经搜索了几个小时来解决,但到目前为止没有任何帮助。
对于这个问题,我很感激任何一种方法。
我正在我的应用程序中构建一个与消息应用程序非常相似的页面。此页面的顶部有一个工具栏,其正下方有一个集合视图,集合视图下的视图包含用于发送消息的文本字段。
集合视图是两个用户之间的消息列表。它由使用自动布局的自调整大小的单元组成。
我按照许多人的建议添加了一个 KeyboardNotification 侦听器,以便在键盘引入屏幕时向上移动我的文本字段。为了使其工作,包含文本字段的视图有一个约束,使其保持在底部布局指南。当键盘被调出时,该约束上的常量会发生变化以适应键盘高度。
这很有效,但我的问题在于,为了动画化约束更改,必须调用view.layoutIfNeeded()
. 这会导致我的集合视图单元格短暂调整大小并设置动画。这非常烦人,看起来很糟糕,所以我问:如何layoutIfNeeded
在父视图上调用时保持集合视图单元格不动画?
z在 .net Maui 应用程序中,我遇到以下问题:我的集合视图在调试模式下工作正常,但在发布模式下,集合视图仅显示一个白色矩形,而不是图像和两个标签。onClick 函数工作正常:\n这是 xaml:
\n<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"\n xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"\n xmlns:vm="clr-namespace:VegaMaui"\n xmlns:model="clr-namespace:VegaMaui.Model"\n x:Class="VegaMaui.MenuDetails" x:DataType="vm:MenuDetailsViewModel" \n Title="\xd4\xb1\xd5\xba\xd6\x80\xd5\xa1\xd5\xb6\xd6\x84\xd5\xb6\xd5\xa5\xd6\x80"\n BackgroundColor="#f9f9f9"> \n <CollectionView \n RemainingItemsThreshold="5"\n RemainingItemsThresholdReachedCommand="{Binding LoadMoreS}"\n SelectionMode="Single"\n SelectionChanged="OnProdSelectionChanged"\n ItemsSource="{Binding ProdListS}"\n x:Name="prodcollect">\n <CollectionView.ItemsLayout>\n <GridItemsLayout Orientation="Vertical"\n Span="2" />\n </CollectionView.ItemsLayout> \n <CollectionView.ItemTemplate> \n <DataTemplate x:DataType="model:ProductImg"> \n <Grid Margin="5,5,5,5" Padding="1" >\n <Grid.RowDefinitions>\n <RowDefinition Height="Auto" />\n <RowDefinition Height="Auto" />\n <RowDefinition Height="Auto" />\n <RowDefinition Height="Auto" />\n </Grid.RowDefinitions>\n <Grid.ColumnDefinitions>\n <ColumnDefinition Width="*" /> \n </Grid.ColumnDefinitions>\n <Image\n Grid.Row="0" \n Grid.Column="0" \n Source= "{Binding firstPicture}" \n Aspect="AspectFill"/> \n <Label Grid.Row="1"\n Grid.Column="0" \n FontAttributes="Bold"\n …
Run Code Online (Sandbox Code Playgroud) 我有一个UICollectionView填充了一些单元格,我实现了方法- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
这就像一个魅力,但它在滚动时不起作用.这是一个问题,因为滚动是非常敏感的,因此当我的意思是推单元格并调用方法时,我最终滚动没有结果.
所以我想知道如何解决这个问题,并想出了这个:
谢谢你提前
我需要将 ObservableCollection 视图绑定到 FlexLayout(因为我需要自定义外观)。当我将项目绑定到 CollectionView 时,它们的外观与我在 FlexLayout 中直接使用 grid 时获得的外观不同,例如:
当然,这按预期工作,但没有约束力。
<FlexLayout Grid.Row="5"
Grid.Column="0"
Margin="10,15,10,5"
HorizontalOptions="FillAndExpand"
VerticalOptions="StartAndExpand">
<Grid Margin="0,0,0,6"
HeightRequest="20">
<Frame Padding="2"
BackgroundColor="#f1f1f1"
CornerRadius="5">
<Label Grid.Row="0"
Grid.Column="1"
FontSize="11"
Text="some text"
TextColor="DarkGray" />
</Frame>
</Grid>
</FlexLayout>
Run Code Online (Sandbox Code Playgroud)
这里一切都绑定正常,但外观就像一个 ListView:
在后面的代码中:
xEspecialidades.ItemsSource = StringCollection;
Run Code Online (Sandbox Code Playgroud)
在 XAML 中:
xEspecialidades.ItemsSource = StringCollection;
Run Code Online (Sandbox Code Playgroud)
我发现这个线程https://github.com/xamarin/Xamarin.Forms/issues/8234 但无法使其工作。Visual Studio 一直说找不到 FlexItemsLayout。有没有办法做我想做的事?
collectionview ×10
ios ×5
.net ×2
c# ×2
objective-c ×2
swift ×2
wpf ×2
xcode ×2
animation ×1
autolayout ×1
cells ×1
data-binding ×1
highlight ×1
image ×1
maui ×1
paging ×1
release ×1
scroll ×1
silverlight ×1
swift3 ×1
xamarin ×1