我想在Xamarin表单中实现水平滚动列表视图,并且我尝试了几个库,但找不到好的解决方案。这是可能的Xamrin形式(没有呈现),并有工作库我可以使用?水平列表视图Xamarin表格
回答
尝试https://www.nuget.org/packages/HorizontalListView1.1/
使用范例:(XAML)
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="test.ListPage" xmlns:Controls="clr-namespace:test;assembly=test">
<Controls:HorizontalListView ItemsSource="{Binding Categories}" ListOrientation="Horizontal">
<Controls:HorizontalListView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Name}" Grid.Row="0" YAlign="Center" />
</DataTemplate>
</Controls:HorizontalListView.ItemTemplate>
</Controls:myControl>
谢谢。我会试试这个。 – droidNDK
中序,让你必须创建一个自定义的滚动型水平滚动列表视图的注意和XAML
使用这种自定义控件public class ImageGallery:ScrollView { readonly StackLayout _imageStack;
public ImageGallery()
{
this.Orientation = ScrollOrientation.Horizontal;
_imageStack = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
this.Content = _imageStack;
}
public IList<View> Children
{
get
{
return _imageStack.Children;
}
}
public static readonly BindableProperty ItemsSourceProperty =
BindableProperty.Create<ImageGallery, IList>(
view => view.ItemsSource,
default(IList),
BindingMode.TwoWay,
propertyChanging: (bindableObject, oldValue, newValue) => {
((ImageGallery)bindableObject).ItemsSourceChanging();
},
propertyChanged: (bindableObject, oldValue, newValue) => {
((ImageGallery)bindableObject).ItemsSourceChanged(bindableObject, oldValue, newValue);
}
);
public IList ItemsSource
{
get
{
return (IList)GetValue(ItemsSourceProperty);
}
set
{
SetValue(ItemsSourceProperty, value);
}
}
void ItemsSourceChanging()
{
if (ItemsSource == null)
return;
}
void ItemsSourceChanged(BindableObject bindable, IList oldValue, IList newValue)
{
if (ItemsSource == null)
return;
var notifyCollection = newValue as INotifyCollectionChanged;
if (notifyCollection != null)
{
notifyCollection.CollectionChanged += (sender, args) => {
if (args.NewItems != null)
{
foreach (var newItem in args.NewItems)
{
var view = (View)ItemTemplate.CreateContent();
var bindableObject = view as BindableObject;
if (bindableObject != null)
bindableObject.BindingContext = newItem;
_imageStack.Children.Add(view);
}
}
if (args.OldItems != null)
{
// not supported
_imageStack.Children.RemoveAt(args.OldStartingIndex);
}
};
}
}
public DataTemplate ItemTemplate
{
get;
set;
}
public static readonly BindableProperty SelectedItemProperty =
BindableProperty.Create<ImageGallery, object>(
view => view.SelectedItem,
null,
BindingMode.TwoWay,
propertyChanged: (bindable, oldValue, newValue) => {
((ImageGallery)bindable).UpdateSelectedIndex();
}
);
public object SelectedItem
{
get
{
return GetValue(SelectedItemProperty);
}
set
{
SetValue(SelectedItemProperty, value);
}
}
void UpdateSelectedIndex()
{
if (SelectedItem == BindingContext)
return;
SelectedIndex = Children
.Select(c => c.BindingContext)
.ToList()
.IndexOf(SelectedItem);
}
public static readonly BindableProperty SelectedIndexProperty =
BindableProperty.Create<ImageGallery, int>(
carousel => carousel.SelectedIndex,
0,
BindingMode.TwoWay,
propertyChanged: (bindable, oldValue, newValue) => {
((ImageGallery)bindable).UpdateSelectedItem();
}
);
public int SelectedIndex
{
get
{
return (int)GetValue(SelectedIndexProperty);
}
set
{
SetValue(SelectedIndexProperty, value);
}
}
void UpdateSelectedItem()
{
SelectedItem = SelectedIndex > -1 ? Children[SelectedIndex].BindingContext : null;
}
}`
现在你可以使用XAML中的自定义滚动型得到一个水平滚动列表
<custom:ImageGallery ItemsSource="{Binding ImageList}" HeightRequest="100"> <custom:ImageGallery.ItemTemplate> <DataTemplate>
< - 通过旋转的ListView> </DataTemplate> </custom:ImageGallery.ItemTemplate> </custom:ImageGallery>
谢谢。我会试试这个。 – droidNDK
一些创建水平列表视图 - 布局和相关的东西,然后旋转元素。
这是一个破解,你必须确保它不会妨碍你的布局(不要把它放在网格中)。但它工作正常。
- 1. 降低水平列表视图的高度 - xamarin表格
- 2. Xamarin格式的列表视图项水平
- 3. iOS水平列表视图
- 4. 的水平列表视图
- 5. 可可单行表格视图或水平列表视图
- 6. JavaFX水平图表列表
- 7. 水平曲线列表视图
- 8. Xamarin.Forms中的水平列表视图
- 9. Android的列表视图水平
- 10. 水平列表视图自定义列表视图项不显示视图
- 11. Xamarin窗体水平列表视图显示来自ObservableCollection的图像
- 12. Flex水平贴图列表
- 13. 网格中列表视图项后的水平线
- 14. Xamarin水平视图与按钮
- 15. Xamarin窗体列表视图
- 16. 水平列表视图中添加页脚视图
- 17. 利用水平滚动视图和下面的列表视图
- 18. Android:垂直滚动视图中的水平列表视图?
- 19. 网格水平视图
- 20. 页面有水平列表视图,并在屏幕上显示该列表数据Xamarin表单
- 21. Xamarin表单列表视图行宽
- 22. Xamarin表单列表视图绑定
- 23. 水平列的表
- 24. 水平列表框
- 25. PyGTK水平列表
- 26. Flex水平列表
- 27. 表/集合视图的水平滚动
- 28. android:水平拉伸表面视图
- 29. 表格内联和水平与图像
- 30. 将列表视图划分为列,使用水平滚动(wpf)
也许是CarouselView? –